Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
4
votes1
answer325
viewsA: Methods with Dynamic C#parameter
Honestly, this way will generate you more rework than help you. First, I’d leave your class addParametrosSql generic. By the way, the name is horrible. I will choose a better name, ok? public class…
-
4
votes1
answer66
viewsA: Parameterizing Dataset in C#
I didn’t understand why you separated the procedure into two methods. Anyway, the error doesn’t seem to be from the Binding of DataSet with the GridView, and yes with the method Select. Your code…
-
0
votes1
answer202
viewsA: Error rendering Partialview in a View
You’re going through it: @model MeuProjeto.Models.AccAvaliacaoComposicaoCorporal Your Partial asks for this: @model IEnumerable<MeuProjeto.Models.AccAvaliacaoComposicaoCorporal> Change @model…
-
3
votes3
answers2573
viewsA: Is it possible to avoid using ifs in these cases?
At all costs no. I would say that in several situations they are avoidable yes. The idea is to establish a programming discipline that does not complicate your code unnecessarily. I’ll show you some…
-
3
votes1
answer217
viewsA: Correct way to update a Model from a Viewmodel
Depends on the bank’s technology. Using Entity Framework Option 1 is better. When mapping your Viewmodel for a Model and mark the entry for change, the Entity Framework checks whether this entity,…
-
5
votes1
answer441
viewsA: Generic Dbcontext Dbset Method with Entity Framework
Is there any way I can call GridPadrao generic? Yes. Using generic. public static DbSetExtensions { public static GridDTO GridPadrao<T>(this IDbSet<T> entities, ParametrosGridDTO…
-
2
votes1
answer182
viewsA: Microsoft SQL Server for Mysql
If I were you, I’d change your class a little bit DALConexao: namespace DAL { public class DALConexao<TConnection> where TConnection : class, IDbConnection, new() { private String…
-
2
votes2
answers849
viewsA: Best way to make class relationship
The beginning is correct. Navigation properties need to be defined for use by the Entity Framework, for example: public class Pedido { public int PedidoId {get;set;} public virtual…
-
0
votes1
answer31
viewsA: Role Default Value in a dropdown
In fact it won’t work. You’re writing ViewBag.Roles N times: one for each execution of foreach: foreach (var user in result) { user.Roles = userManager.GetRoles(user.UserID); ViewBag.Roles = new…
-
0
votes1
answer739
viewsA: Entity Framework List
Here you said how are the relationships between your tables. Assuming that, I can do the following: CliCliente cliente = db.CliCliente .Include(c => c.Tabela2) .Include(c => c.Tabela3)…
-
1
votes1
answer774
viewsA: Transaction with multiple queries
Actually this is not the problem. You just haven’t enabled support for the transaction coordinator, whose steps are here. The code is almost all right. Just take this: // Código adicional para…
-
2
votes1
answer151
viewsA: Iterations within Transactionscope
What are the losses caused by a TransactionScope very long? Performance penalties, basically. If the transaction scope still asks lock exclusive, the system as a whole gets slow. It would be…
-
3
votes1
answer259
viewsA: Creation of Foreignkey
Several things wrong, and some missing. I’ll start with Setor: [TableName("Setores")] // Use isto para definir corretamente o nome da tabela. // A inflexão em inglês pluraliza errado o nome. public…
-
2
votes2
answers88
viewsA: Action Edit in Viewmodel
The way I see it, I don’t think you understand any of the explanations. This isn’t gonna work: AnamineseViewModel anamnese = new AnamineseViewModel(); anamnese.CliCliente.CliId = cliente.CliId;…
-
1
votes1
answer184
viewsA: How to do Edit action with view model?
Basically it is the same principle of creation, but some more details need to be observed: The identifier of the Model original needs to exist somehow; You will need to bring from the bank the Model…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
0
votes1
answer259
viewsA: "Invalid column name" MVC
The name of the column in bank is wrong. It should be SetorId, and not Setor_Id. Do not use underscore to map your entity keys, as they are not part of the Entity Framework convention. You are using…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
5
votes1
answer762
viewsA: How does Sqlbulkcopy work?
The SqlBulkCopy works with some kind of service provided by bcp utility, sending it the data to be entered? The source of the class SqlBulkCopy is here. Search for INSERT BULK within this source. It…
-
5
votes3
answers629
viewsA: EF6 + Postgresql - 22021: invalid byte Sequence for encoding "UTF8": 0xc9 0x52
Bad news. The Npgsql team gave up SQL_ASCII support. Directly forcing the use of LATIN1 for strings, this user managed to use SQL_ASCII in his system. The problem is that this can hardly be used…
-
4
votes1
answer1323
viewsA: Map View - Entity Framework
This is totally wrong. If you have a context managed by the Entity Framework, you cannot map read-only objects on it. Create a second reading-only context, like this: public class ReadOnlyContext:…
-
0
votes1
answer249
viewsA: Enable Iframe in Asp.net application
In his Global.asax.cs, define the following: protected void Application_PreSendRequestHeaders() { Response.Headers.Remove("X-Frame-Options"); Response.AddHeader("X-Frame-Options", "AllowAll"); }…
-
5
votes2
answers563
viewsA: Prompt Expression<Func<T, bool>> via parameter using object that is in a foreach
I will need to divide this answer into two: the first part will talk about traditional Linq. The second part will talk about Entity Framework. Linq Tradicional I rode this Fiddle explaining how it…
-
6
votes1
answer372
viewsA: Select with date over 20 years
Select * from Pedidos Where dataPedido > DATEADD (yy, -20, GETDATE()); See more here.…
sql-serveranswered Leonel Sanches da Silva 88,623 -
8
votes2
answers367
viewsA: Difference between . NET Framework for Entity Framework
After all, what exactly would Target framework? Is the version of framework .NET for the entire project. Newer versions have more features, more features, and language specification, such as C#,…
-
4
votes1
answer130
viewsA: Difference in content formatting in Textarea and notepad
Because of the source used inside <textarea>. Possibly the stylesheet is not using a monospaced font. Try to define a style like this: textarea { font-family: Consolas, Lucida Console, Courier…
-
2
votes1
answer1270
viewsA: Read file that is on Solution in C#
First you need to configure the file to be copied to the bin in the build of his Solution: Right click on the file > Properties (or select the file and press F4; In Build Action, select Content;…
c#answered Leonel Sanches da Silva 88,623 -
2
votes1
answer51
viewsA: How to stay with the selected item in a select after page transition?
GET That’s why the parameterization GET was made: so that, in a page change, the filters remain. How is the use of this? I’m guessing you have one <form> at some View your: @using…
-
3
votes2
answers940
viewsA: File import and read
There is a Better Option 3? There is a. Start by installing Filehelpers and the Bulkinsert for the Entity Framework. Use something similar to option 2: using FileHelpers; using…
-
3
votes2
answers223
viewsA: Which database is ideal for my scenario?
There is still the possibility of SQL Server Express Localdb, which is practically your SQL Server, but based on a single MDF file. The impact on your system will be very small. Another thing you…
-
2
votes2
answers85
viewsA: Unsaved relationships
Logic won’t work the way it is because you’re not necessarily creating elements of Tabela2, Tabela3, Tabela4 and Tabela5 throughout the creation of CliCliente. But if they don’t exist yet, this…
-
1
votes1
answer58
viewsA: Error logging data in Viewmodel
There are some problems there. As all relations are from N to 1 (and not from 1 to N), the Partials will have to be called like this: @Html.Partial("_PartialCliente", Model)…
-
1
votes1
answer33
viewsA: Explanation for the error in the following code
I turned your code into a Fiddle. Notice that this: Console.WriteLine(Tot+=x[i]); Is inside the for, then it will be printed every new iteration. Another thing is that you’re not assigning Tot on…
c#answered Leonel Sanches da Silva 88,623 -
0
votes2
answers1278
viewsA: Adding consecutive integers to a list - Python
'Cause you’re reading a position that doesn’t exist when i == 3 (last iteration). The correct one would be: i = 0 soma = 0 lista = [1,2,3,4] soma += lista[0] for i in xrange(0, len(lista) - 1): if…
python-2.7answered Leonel Sanches da Silva 88,623 -
5
votes2
answers2267
viewsA: How Viewmodel works on Asp.net mvc
Make a Controller empty. My suggestion: public class AnaminasesController : Controller { protected SeuContexto contexto = new SeuContexto(); public ActionResult Index() { /* Liste aqui o que pode…
-
1
votes1
answer366
viewsA: How to load the latitude and longitude pairs to a C# object and work them?
There is the geocoordinate object in System.Device.Location which serves precisely to work with coordinates. He has the methods Latitude and Longitude.…
-
1
votes2
answers808
viewsA: Search Filter
I think that this answer here can be useful for you. In your case, you can make a Viewmodel whose fields are Nullable: public class ParametrosPesquisaViewModel { public DateTime? DataInicial { get;…
-
3
votes2
answers167
viewsA: View with Ienumerable and Entityframework
1 - I need to create a specific Model to represent this View? Not necessarily. The grouping and totalization functions can be done in the View, if you want. 2 - in the database I can view this…
-
3
votes2
answers730
viewsA: ASP.NET MVC session
RedirectToAction opens a new request and therefore evaporates the data from Session. I’d say that’s not the best way to do what you want. Prefer to use instead TempData, who has a longer life span:…
-
7
votes2
answers1094
viewsA: How to declare a function within another function in C#?
Directly, no. But you can declare a Action or delegate, or Func<>, which is almost the same thing. using System; public class Program { delegate void Teste2(); public static void Main() {…
-
2
votes1
answer165
viewsA: Entity Framework, you doubt the solution structure (app.config and package.config)
Some comments before the reply: Entity Framework is already a ORM. You don’t need to create a project to envelope it; You do not need to separate the domain from the ORM layer. The correct is the…
-
10
votes1
answer1372
viewsA: Pass two templates to a sign-up view
Following the previous hook, if you have the relationship of Aba for Tela, the selection made here already contemplates the lazy load of Tela and of TelaFuncao: var abaQuery = _sigconEntities.Aba…
-
5
votes1
answer302
viewsA: Problem with left Join using Entity framework
There are several things that need to be said for those who come from other development paradigms, and I believe this answer will be ideal for this. Premises of those coming from other architectures…
-
4
votes2
answers382
viewsA: What is the Microsoft Bot Framework?
The name says it all: a robot. A robot performs some actions automatically, such as reading and interpreting user messages, monitoring chat rooms, sending scheduled messages, and so on. Here is the…
-
7
votes2
answers375
viewsA: A LINQ query returns what type of data?
In the above example, what is the type of data that would be assumed by the variable query? An object that implements IQueryable<T>, being T the guy Pessoa. IQueryable is not an enumeration.…
-
1
votes1
answer269
viewsA: Error generating excel file
Avoid using Microsoft.Office.Interop.Excel in ASP.NET MVC projects. It depends on logging as COM library. In your place, use the library Epplus. It does not need COM registration and is quite…
-
1
votes1
answer2049
viewsA: Foreach in Select and List
When I do Where or Select in a list the operation is executed at the time the method is called or is only executed when I access the items or use ToList()? Whereas LINQ to SQL or Entity Framework,…
-
2
votes1
answer58
viewsA: Error using Split inside Select
I already managed to solve the problem using ToList and doing the Select with Split in it, but I would like to understand what is the reason for the problem. The reason begins in this explanation.…
-
5
votes2
answers1328
viewsA: Is it safe to use List with Parallel.Foreach?
My method is working, but it is very slow, so I want to parallelize the calls. So I searched the Parallel.ForEach easily solves this problem, but it is safe to use it with List? Not List and any…
-
3
votes1
answer100
viewsA: Show data from multiple models in the view
The quick way to resolve (though slow in execution and fragile) is by defining the View as follows: @model IEnumerable<dynamic> Only this way there is no checking of types in design time, and…
-
5
votes2
answers235
viewsA: How to create a cross-platform app?
The version of . NET that allows this cross-platform resource is Mono. Mono has a tool that checks if your project is fit to be migrated. Once done, it may be necessary to change something,…
-
1
votes2
answers4277
viewsA: applicationx-www-form-urlencoded with Httpwebrequest
It wouldn’t just be the case escape the Token characters? var tokenEscapado = Uri.EscapeDataString(token); HttpUtility.UrlEncode will not work because it is for URL’s, and what is giving problem is…