Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
1
votes1
answer138
viewsA: How NOT to cascade delete records with 1-n relationship using Entity Framework?
Making foreign key optional. Modify Category to the following: public class Category { public int Id { get; set; } public int? MenuId { get; set; } public string Name { get; set; } public virtual…
-
1
votes1
answer238
viewsA: Performance in string filter queries vs foreign key
I’m losing performance by not having a relationship through foreign key and just keeping the UserId on a property string? It is. In fact, you can associate your ApplicationUser normally to any other…
-
1
votes1
answer1629
viewsA: Error loading Antlr3.Runtime
Possibly corrupted the package. Open the Package Manager Console and run the following command: PM> Update-Package Antlr -reinstall
-
3
votes1
answer283
viewsA: Fill Combobox with Dapper
One thing Dapper doesn’t clarify is that his return isn’t exactly structured the way a data source of a component . NET waits, so I wrote an extension method that converts the result to something…
-
2
votes3
answers1160
viewsA: Validation to check if the record is being used before deleting
Your system actually uses Entity Framework yes. The correct way to warn the user that the registry cannot be deleted is something like: var registro = context.Registros.Include(r =>…
-
28
votes2
answers1875
viewsA: Code plagiarism
When it comes to our intellectual creation, to what extent would plagiarism copy and paste excerpts of another code, available on the Internet, in my (common practice)? It all depends on the code…
licenseanswered Leonel Sanches da Silva 88,623 -
1
votes2
answers1558
viewsA: Global variable query in a controller
This is quite a gambit. What you can do is install Redis and write this "status" per user to a key outside the ASP.NET MVC application. Access to this variable is done for this client.…
-
2
votes1
answer502
viewsA: Authenticate user efficiently and quickly (without setbacks, Identity x Manual)
For the validation I thought about using Identity, because what I saw makes things easier, however, I did not see from scratch, I made an example and some changes minimums. And then I was in doubt,…
-
2
votes1
answer357
viewsA: Fluent Nxn mapping of Classes with composite key
I see no need to use EntityTypeConfiguration for something so simple. The Models can stay like this: public class Cliente { [Key] public int Id { get; set; } public int EscritorioId { get; set; }…
-
3
votes1
answer478
viewsA: A dynamic field for each database record
It is a classic case of the use of nuget pack BeginCollectionItem. It is not native to ASP.NET MVC or Razor. It needs to be installed. I’ve answered several questions about. If necessary, please…
-
5
votes1
answer215
viewsA: What is the best way to display in Python? Double asterisk or Math.Pow?
Speed The operator ** is usually faster than math.pow(). He calls the native function pow, which, by the way, accepts a module argument. Usually it is better for integers. Type safety math.pow()…
pythonanswered Leonel Sanches da Silva 88,623 -
2
votes3
answers369
viewsA: MVC and dynamic language change
The most elegant scheme I’ve ever found for PHP is in Cakephp, in the module i18n. Basically, the whole system is defined with internationalization functions like this: __("MinhaString")…
-
2
votes1
answer817
viewsA: Catch AD user Asp net mvc
When creating the project, Visual Studio offers this option. When creating a project, click Change Authentication as in the screen below: On the next screen, click Windows Authentication: If the…
-
1
votes1
answer79
viewsA: Grab Control Not Typed in View Typed
I’d trade the boolean for a Enum: public enum TipoAtendimento { Particular, Convenio, Domiciliar, LocalProprio } public class BuscarProfissionalModel { public string NomeTipoConvenio { get; set; }…
-
3
votes1
answer2091
viewsA: Make a button to add properties to a list using Begincollectionitem C#
Alter the View main to the following: @model meuprojeto.ViewModels.PessoaViewModel // resto da view... <div id="tab-3" class="tab-pane"> @if (Model != null &&…
-
6
votes2
answers141
viewsA: How to bulk assign variables in Python?
Is very similar: (a, b, c) = 1, 2, 3
pythonanswered Leonel Sanches da Silva 88,623 -
2
votes1
answer1376
viewsA: Get input value from a textbox in Asp.net mvc
The correct way to do this is through a <form>. Using MVC and Razor, it is used as follows: @model MeuProjeto.Models.MeuModel @using (Html.BeginForm()) { @Html.TextBoxFor(model =>…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
2
votes1
answer36
viewsA: How to open an external MVC3 application on MVC5?
The answer to that is far from simple. It is based on Single Sign On (SSO) between two different sites, using some SSO library like the Ssolib. Here is a (huge) tutorial on how to do. This other…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
4
votes1
answer2229
viewsA: Identifying the foreign key in the Codefirst Entity Framework
Objectively speaking, through a class called ForeignKeyPropertyDiscoveryConvention. The operation is explained here. Roughly, the way the Entity Framework performs the discovery of the foreign key…
entity-frameworkanswered Leonel Sanches da Silva 88,623 -
8
votes1
answer189
viewsA: Different connectionstring for different builds
The procedure is very similar to this answer here, only that for <connectionstrings>. For example: Web.Release.config <configuration…
-
68
votes3
answers8159
viewsA: When to use Entity Framework with Repository Pattern?
Never Simple as that. Implementing one repository on top of another doesn’t make any sense. This is easy to see by analyzing how the DbSet. DbSet implements IEnumerable and IQueryable (because…
-
8
votes2
answers420
viewsA: How to extend Pocos from the Entity Framework by encapsulating business rules?
This question is a collection of problems. Even if you don’t consider it, I will use it as a guide to what not to do in an ASP.NET MVC application. I’m developing a 3 layer ASP.NET MVC system. My…
-
4
votes1
answer957
viewsA: Form using Begincollectionitem gets null viewModel in foreach
The code is perfect. That’s what it is to do. Now you mount the Viewmodel so that all this code makes sense. That is to say: // GET: Pessoas/Create public ActionResult Create() { var pessoaViewModel…
-
11
votes2
answers11475
viewsA: What is the git diff command for?
diff serves to verify differences between commits, files and directory trees. Examples: git diff: Displays all differences between your local copy and the synchronized index; git diff –cached:…
gitanswered Leonel Sanches da Silva 88,623 -
17
votes4
answers1541
viewsA: What is the difference between "++$variable" for "$variable++"?
This example you put up is not very good because the variable is always printed after the event that manipulates the variable. A better example would be like this: $i = 0; while ($i < 3) { echo…
-
1
votes1
answer282
viewsA: Tempdata works on Localhost but doesn’t work when published
This is the most wrong way to do it. First of all, there is no need to separate the code in this way, because every Action of a Controller necessarily need to return a concrete result. You mounted a…
-
9
votes1
answer206
viewsA: Doubt with Codefirst Entityframework
For two reasons: Because it is the Entity Framework that assembles this object for you; Because it is not necessarily a list or a collection. It can be a Dynamic Proxy, which makes the lazy loading…
-
1
votes1
answer527
viewsA: Return database value to textbox Asp.net MVC
You using your wrong View. Change to the following: @model MeuProjeto.Models.BoletoModel // Preencha o nome da classe com o namespace. Aqui chutei um só pra você pegar a ideia. <label>…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
7
votes1
answer7943
viewsA: Pass parameter to a C# MVC Controller
Some things were missing: In his View Index: @{ ViewBag.Title = "Index"; } @using (Html.BeginForm()) { <h2>Digite um Numero: @Html.TextBox("id")</h2> <input type="submit"…
-
12
votes2
answers437
viewsA: Performance difference of Any() and Count()
Depends on the type of enumeration. If it is based on ICollection<T>, .Count (property, not method) is faster because the value is already previously calculated within the structure…
-
2
votes2
answers772
viewsA: Register only some data from a C# Asp.net MVC 5 form
Nested forms don’t, but you can have one View that expands the form according to your need for addresses. This can be done through the package Begincollectionitem. I have written several responses…
-
4
votes1
answer281
viewsA: SQL Server Full-Text-Search
I’ll put some alternatives I know. Alternative 1: String Similarity Test I removed that solution from here, who uses fuzzy search. CompareText returns an index between 0 and 100, being 100 for two…
sql-serveranswered Leonel Sanches da Silva 88,623 -
10
votes2
answers141
viewsA: How to Lambda in Extension Methods with Multiple Lists?
If it’s Entity Framework, I think the list comes from a context, then I won’t use a separate list to answer. I will answer from the same context, because the construction of a list from a data…
-
2
votes1
answer80
viewsA: Filter by group and minimum value
Well, I don’t know the name of the entity. I’ll assume it is Registro, then the DbSet is called Registros by convention. This takes each person’s oldest due date: var registros = contexto.Registros…
-
7
votes1
answer915
viewsA: Test classes with dependencies (C# + Entity Framework)
I will pass a way of my testing. I do not know if it is the best, but it can be a starting point for us to produce something more concise and coherent. The testing method and Mocks gypsy It took me…
-
1
votes1
answer3137
viewsA: Create a dropdownlist and get the selected id Asp.net MVC
Set an anonymous object in the argument HtmlAttributes as follows: @Html.DropDownListFor(modelItem => item.EscolhaBanco, new SelectList(new List<Object> { new {value = 0, text = ""}, new…
-
5
votes2
answers296
viewsA: How to make a LINQ/lambda and consume it in the view?
It doesn’t make sense here: var RadioAtivo = db.Radios .Where(p => p.Ativo == true && p.Mp3 == false) .Take(1); return View(RadioAtivo.ToList()); If you want to present only one element…
-
4
votes2
answers2885
viewsA: Blocked cross-origin request
The most elegant solution I know implements a Attribute which allows accepting the request depending on the Action or of Controller called. I do not recommend registering the Attribute globally. 1.…
-
3
votes3
answers517
viewsA: Create FTP access to a virtual directory on Azure
Azure does not implement the FTP protocol on its websites. It is another tool. It is called Webmatrix. You can download it here. EDIT I think this answer is different. Now there is a way to publish…
-
1
votes4
answers228
viewsA: Read XML documentation generated by Visual Studio
Yes, the Sandcastle. There is still the NDOC and the Docproject that may be useful.…
-
0
votes1
answer423
viewsA: Make anime and manga gallery in c# desktop
I believe it can be done in Windows Forms or else in Xaml. XAML is even more suitable because it’s already ready for other Microsoft technologies, such as Tablets and Phones. I would not do in…
-
1
votes1
answer195
viewsA: Search Data with jQuery
This is wrong here: $.getJSON("/Cursos/RetornaAluno" + cpf + "&formato=json", {}, function (data) { ... }); Possibly the default route does not even accept CPF as argument, so you need to…
-
3
votes1
answer469
viewsA: How to run a web application on IIS without hosting the source code on the machine?
Usually in Deploy everything will be compiled, except ASPX. To pre-compile your ASPX, do the following: Right click on the project > Properties; In Post-build Event command line, put the command:…
-
6
votes1
answer2951
viewsA: LEFT JOIN using Linq
Considering Extension Methods about Entity Framework, there is not exactly the concept of LEFT JOIN. What there is is a charge of Responsavel who may or may not have Filho. I mean, I imagine your…
-
1
votes1
answer651
viewsA: Child actions are not allowed to perform redirect actions. MVC 5
The error already says it all. You cannot use a Action call for a View to redirect requests. The reason is to avoid cascading redirects. The correct in your case would be View main do the POST(by…
-
1
votes1
answer166
viewsA: Error Identityconfig
Packages are right, but outdated. Open the Package Manager Console (View > Other Windows > Package Manager Console) and type the following: PM> Update-Package…
-
6
votes2
answers1573
viewsA: How to access next and previous record with C# using Entity Framework
The most elegant way I know is used to create pagination in ASP.NET MVC applications, using Skip() and Take(): var registroAtual = 6; var registroAnterior = contexto.Entidade.Skip(registroAtual -…
-
2
votes1
answer210
viewsA: Table relationship - EF
Your code is quite out of standard, and this makes the Entity Framework may not work properly. I’ll start with the entity OrdemDeServico: [Table("OrdemDeServico")] public class OrdemDeServico {…
-
2
votes2
answers17227
viewsA: Unable to load file or Assembly 'Webgrease, Version=1.3.0.0, Culture=neutral
Reinstall Webgrease with a more current version. Open the Package Manager Console (View > Other Windows > Package Manager Console) and use the following command: Update-Package WebGrease This…
-
2
votes1
answer173
viewsA: Asp Net MVC Authentication Extending Authorizeattribute
I’m guessing you’ll use C# in the solution. Modify the following in the file Global.asax.cs: public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() {…