Posts by Gabriel Coletta • 1,787 points
63 posts
-
0
votes1
answer40
viewsA: API Amazon Product Advertising
Requestthrottled is a way for Amazon to prevent you from making too many requests to your API in a short amount of time (According to them, every 1 second only 1 request is possible). It is a…
-
1
votes1
answer44
viewsA: Error in expression
There is no SQL command for your Convert.Toint32. When it arrives at the stage of translating its expression to SQL the framework cannot translate a result, generating this error. To avoid this kind…
-
3
votes1
answer316
viewsA: How to automatically minify CSS/Javascript in ASP.NET MVC5
You have the Framework Bundle. Inside your printer App_Start create a class BundleConfig.cs and add: public static void RegisterBundles(BundleCollection bundles) { //para javascript, você pode fazer…
-
8
votes2
answers5112
viewsA: What is a Dataset and what is its function?
First you must understand what ADO.NET. It is an access layer between some data store (not limited to the database) and your .NET. application.In your case, to access the SQL Server information…
-
3
votes2
answers64
viewsA: Inherit comments from a virtual object
With Resharper (and possible other tools), you can replicate the comment with Alt+Enter in the setting, you will have an option to copy the base documentation. Even with this possibility, be aware…
-
1
votes2
answers184
viewsA: EF - Navigating through Icollection
As commented, your relationship 1 to N is wrong. The foreign key should be inside Author, since it is the Author who should know which book it relates to. About the collection, ICollection does not…
-
1
votes3
answers1166
viewsA: How to access and stop a Thread? ASP.NET C#
What you’re trying to do is a bad design. Note that, your request is returned without thread completion, but what if the thread generates an exception and does not correctly terminate its operation?…
c#answered Gabriel Coletta 1,787 -
1
votes1
answer100
viewsA: What precautions should I take when creating tables with 1:1 relationship?
Trying to model smaller tables is undoubtedly a good practice, for this there are levels of database normalization to guide you in this process. Your test does not have results as noticeable because…
-
6
votes3
answers285
viewsA: What is the function of #if false in C#?
In your case, the result will be the same. But many code refactoring/analysis tools can mark code comments as a Smells code (which is actually). Thinking about the compilation of your code, the…
c#answered Gabriel Coletta 1,787 -
4
votes1
answer722
viewsA: Is it necessary to pay something to use Asp.net?
The . NET framework is free, both the version of ASP.NET and ASP.NET Core. What may have made the confusion is that formerly the . NET was all in Microsoft technology that is paid (Windows Server,…
-
4
votes2
answers99
viewsA: Stackoverflowexception in c# by Linux visual studio code
Note that all your properties your SET accessor recursively calls itself, that’s your problem. If you want to encapsulate this way, you need a private field to hold these values. private string…
-
2
votes5
answers3081
viewsA: How to decide between using for or foreach?
They both do pretty much the same thing... They both do the same thing when we think about going through a collection. So how is it possible to know when to use one or the other? Depending on your…
-
1
votes1
answer79
viewsA: Nhibernate consuming a lot of memory
CLR does not do automatic cleaning in this case, so Dipose and Close. Database connection frameworks "package" a whole complicated job of allocating memory on the server, making a connection to the…
-
0
votes5
answers371
viewsA: Validate model before inserting in the database
Let’s go by part. When you said "model that comes from the request" I assume it is a Dto, a Viewmodel or any name for an object that only carries attributes. It is not interesting to use these…
-
1
votes2
answers266
viewsA: How to use Distinct() or Groupby() in a list that returns an anonymous type?
The problem is your Idnavio is a unique value. The Enumerable.Distinct() uses Object methods to do its job. In the case of anonymous type the compiler will override the Object.Equals() and the…
-
5
votes2
answers265
viewsA: Unexpected result in using Parallel.Foreach
List is not thread-safe, what may be happening is that in some cases two threads will try to add an item at the same time, this can generate something unexpected (such as adding only one object or…
-
0
votes1
answer355
viewsA: How to enable Migrations to Identity in Asp.net MVC
He’s complaining because you have two context with the same name (Applicationdbcontext.Cs) within your solution. The solution is to delete your Context from your MVC layer or rename any of the…
-
0
votes1
answer38
viewsA: doubts generic class Asp.net mvc
I wonder if it’s really right to declare this property and this builder this way or if I should instead declare Irepositorio get the Repositorio straight since the Repositorio inherits from…
-
5
votes6
answers6243
viewsA: check repeated number inside the array c#
Assign your array within a Hashset, as it does not accept repeated values, and then you compare the sizes of both and will know how many values were repeated: int[] array1 = { 2, 5, 8, 10, 2, 23, 2,…
c#answered Gabriel Coletta 1,787 -
2
votes1
answer291
viewsA: Connectionstring returning null
Your connectionstring must exist within the project that has the executable, in the case of Asp.net must exist within the web.config or other file. config that is referenced by web.config. In your…
-
2
votes1
answer4221
viewsA: Asp.net web api From Ri and From Body when to use?
There are two attributes for you to make explicit which will be the parameter Binding that your API will use. By default, the framework will map almost all objects as a JSON that comes in the…
-
1
votes1
answer37
viewsA: Flag environment when sending email to user
You could flag your web.config, for example: <appSettings> <add key="ambiente" value="Produção" /> </appSettings> And to access it, you would use: var ambiente =…
-
2
votes1
answer135
viewsA: Map classes that inherit Id from another Entity - EF Core class
You need to map in the People configuration to create it correctly: ... builder.HasOne(u => u.Filial) .WithOne(p => p.Pessoa) .HasForeignKey<Filial>(b => b.FilialId); ...…
-
1
votes2
answers275
viewsA: How to access the database directly from my model class in an ASP.NET Core project?
Instantiating a context within your model class (which represents a table in the bank) is not an interesting pattern, the domain’s obligation is only to validate itself, and for that you do not need…
-
2
votes1
answer88
viewsA: Entity Framework 6: Context Management Problem
You need to do the Dispose connection with the bank. When you don’t, your first query causes the Entity Framework to track that object (Using the .AsNoTracking() help it not happen). Then when you…
-
0
votes2
answers66
viewsA: Include all child objects (navigation properies) in the Entity search
There is no IncludeAll(), however the ObjectQuery<T>.Include is an all include, so if you put a ObjectQuery.Include(Pessoa.Sexo) you will be carrying both Person and Sex at the same time.…
-
1
votes1
answer86
viewsA: connect to multiple sqlserver databases
By default in the MVC project your web.config will already have two base transformation files: Web.Debug.config and Web.Release.Config. Both are already set to, when compiled, overwrite the main…
-
1
votes1
answer70
viewsA: Doubt about which Inheritance to use in the Entity Framework
It is more interesting to use inheritance, since the principle of reusability is one of the pillars of object orientation. I will make a superficial comment of your proposal using inheritance and…
-
2
votes2
answers678
viewsA: DDD C# - In which layer should I implement the Data export part
I assume that this report module will use some Frameworks to generate these Excel (Epplus example) and PDF (Itextsharp example), so it is interesting you create this in the layer of Crosscutting to…
-
1
votes1
answer122
viewsA: Error trying to save information to the database via Entity Framework
[ForeignKey("UsuarioAbertura")] public long UsuarioAberturaId { get; set; } public virtual Usuario UsuarioAbertura { get; set; } Here you tried to map a ratio from 1 to 1? If you tried this…
-
0
votes1
answer31
viewsA: Settings Many to Many code fast Migration
Entity Framework at the time of User insertion has no tracking of its property ICollection<LocalAtendimento> LocalTrabalho, because of this he believes that you want to insert new…
-
1
votes1
answer729
viewsA: Entity delete table and your relationships
What you need is to activate the cascade exclusion. I believe you are doing something like this: Nota.ItemsNotas.Clear(); Context.Entry(Nota).State = EntityState.Deleted; Context.SaveChanges();…
-
0
votes2
answers219
viewsA: Service to pick up a change in the bank
What you want is to make a Job. Job is a task that will be performed every x value range and you can implement (not recommend) or use a third solution. I know some like the Hangfire, Quartz,…
-
1
votes1
answer1271
viewsA: Error CS0012 The type 'Client' is defined in an Assembly that is not referenced
I’m commenting on the response that was made in the comment to remove her from the "No Response" The problem is that you are trying to use a namespace (using DAO) of an Assembly not yet referenced…
-
3
votes1
answer479
viewsA: How to publish a Webservice using Visual Studio C#?
This occurs when you do not have permission to publish in the application root directory (wwwroot). Try running Visual Studio as an administrator. If it does not work, you will need to give write…
-
1
votes1
answer274
viewsA: Standardize error messages in Dataannotations in Viewmodels classes
Yes, use a Resource for that. In my case it’s called Mensagemerro.resx: [Required(ErrorMessageResourceName = "CampoObrigatorio", ErrorMessageResourceType = typeof(MensagemErro))] Basically I say I…
-
0
votes1
answer135
viewsA: Bank without PK, but I checked the PK by the Entity. Is this a problem?
What puzzles me is the fact that the bank doesn’t have PK. If you were given a database script, a great chance to export the database to script, they did not export the constraints from the…
-
4
votes2
answers122
viewsA: When consuming a service, error occurs in float or double fields in BD
Simple, your DbSet is the type Liberacao and not LiberacaoDTO, so the Entity Framework does not understand the changes. When you do this new Liberacaodto, it is a totally new object that the Entity…
-
2
votes1
answer37
viewsA: Update Queryexpression
The error is because Entitycollection is not a list, it is an object that contains a list. Foreach can only iterate inside the collection with the Getenumerator() method, implemented by Ienumerable.…
-
1
votes3
answers39
viewsA: Cast error while running the Rest service
The problem is here: var _itens = contexto.ItensLibs.Where(it => it.IdOrcamento == id).FirstOrDefault(); When translating SQL to C#, you are assigning a value null for the QTDE property that does…
-
2
votes1
answer810
viewsA: Creation of a Header that is used in the communication of a Webapi
The problem is not the string, you need to specify which header name: var tempo = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"); var httpWebRequest = (HttpWebRequest)WebRequest.Create("teste");…
-
1
votes1
answer48
viewsA: If it has no value to compare, save without comparing
The Enumerable.FirstOrDefault() no argument for default brings the null value when not found a value within your collection. What happens is that if it does not find anything you will be accessing a…
-
4
votes2
answers832
viewsA: Create route to webapi method with parameters via querystring
It is not finding because the {id} of its route is not optional, so all its route has to have a value for {id} or it will not find route. Set your route like this and it will work:…
asp.net-web-apianswered Gabriel Coletta 1,787 -
3
votes1
answer699
viewsA: How to use Viewmodel in MVC 5 C# with Entity Framework?
In this model, I can still use Modelstate.Isvalid for validate the Form Post? Because if it only sends Person data Physical, the Legal Person fields will be null, returned than the…
-
4
votes3
answers750
viewsA: Is it correct in a DTO class to have attributes of two or more tables?
There is no limit to an DTO representing only one entity, the purpose of the DTO is to transfer an object. If your query brought two records, nothing more fair than your DTO represents both. Imagine…
-
1
votes2
answers94
viewsA: Problem when receiving char values
The logic of your WHILE is the problem. While instruction performs an instruction or a block of instructions up to a specified expression is evaluated as false. Reference:…
-
2
votes1
answer57
viewsA: Error saving to bank
By default the Entity Framework will understand that the primary key is being generated Databasegerated and it will ignore the value you manually enter as key, you have to specify that it will not…
-
1
votes2
answers366
viewsA: Return an object from two or more tables to the fields
The concept of DTO is to be a transfer class, you don’t necessarily need to add only the properties of a class to your DTO. It would be something like: var lista = contexto.Liberacoes .Include(lib…
-
1
votes2
answers513
viewsA: Tostring("C3") error
The point is that Nullable inherits directly from the class object, and Object does not have a Tostring() that accepts a string. To make use of Tostring() with a parameter that accepts formatting…
c#answered Gabriel Coletta 1,787 -
3
votes2
answers178
viewsA: How to update all records of all tables that have FK of a table
Taking into account that you have a context Context. var result = Context.Contrato.Include(rel => rel.ItemContrato).FirstOrDefault(prop => prop.Id == id); In this code I charge my Contract…