11
votes
Update only modified fields in Entity Framework
If you are worried about the update statement that it might slow the query down, I would suggest a slightly different approach. You can modify your code to pass in the modified property list. So that ...
8
votes
Recording error messages from an exception
In C# 6 or later you can write it in a single line of code using the null conditional operator (?.) and the null coalescing operator (...
6
votes
Recording error messages from an exception
Assuming you have at least c# 6 (and thus, the null propagation operator), you can simplify it like this:
...
6
votes
Accepted
Configure AspNet.Identity to allow for either username OR email address on login
I know this is an old ticket, but I think I might have an approach that uses only one round trip to the database.
...
4
votes
Website news message edit panel
I've also spotted a few things in your code...
This
if (id != null && id.HasValue)
is exactly the same as
...
4
votes
Website news message edit panel
In addition to Heslacher's points:
Careful with keys like "SuccessMessage" and "FailureMessage": a typo easily happens, so ...
4
votes
Website news message edit panel
Just some quick shoots.
if (id != null && id.HasValue) this two checks are doing the same where the first is just shortcut of the second.
Classes ...
3
votes
Recording error messages from an exception
You can use GetBaseException to get the lowest level exception.
...
3
votes
Accepted
Retrieving all institutions in a specified country
Country.Institutions should never return a null collection, and if it ever does, I'd prefer having a ...
2
votes
DbSet<T> IncludeAll method
Include uses when you want to include ICollection properties or not int, string, ...
2
votes
Accepted
Passing model to _layout.cshtml
Implemented a better design by converting the navigation section into a PartialView and converted UserViewModelBase and ...
2
votes
Accepted
Calling Web API from MVC generic way of approach
I agree as some others have said that in this case, having a layer between Angular and your API is simply bloat / overhead unless there are specific reasons for the extra abstraction. I understand ...
2
votes
Web Api to upload excel file
Naming Convention
current code is not using camelCase naming convention on local variables, and also is not given a good naming ...
2
votes
Open closed principle in a method
Before reviewing micro-design we may focus on overall architecture. You already know that in future you will also need to read an Excel file, it may be a good moment to introduce an abstract base ...
1
vote
Use of C# Razor Syntax in MVC.net view
I would argue that the code in the top should not be moved to Controller.
This of course depends on how you define responsibilities for View, Controller and Model, but I would leave the code in the ...
1
vote
Calling Web API from MVC generic way of approach
The code described above could employ a generic method which could take all the common and repetitive code and just take in the endpoint (e.g. "api/Roles") as a parameter. This could help to reduce ...
1
vote
Website news message edit panel
You do this a lot when accessing the database.
} catch {
return null;
}
Trust me when I say this, you are going to eventually want to know why something ...
1
vote
Defining application flow in ASP.NET MVC5
First off I think its a mistake to call your controller Methods after the view they return. I think this is creating a conceptual link which doesn't really exist.
Secondly, presumably the actions ...
1
vote
Changing a div that contains a view link
This is a nice simple approach to an SPA. I assume you are returning partial pages from your actions.
A slight improvement would be to hide all pages before showing. This way you don't have to touch ...
1
vote
DbSet<T> IncludeAll method
EF knows about all navigation properties. So, instead of using reflection and try to figure it out by myself, I can just ask the DbContext about navigation ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
asp.net-mvc-4 × 101c# × 95
entity-framework × 26
asp.net × 19
mvc × 7
design-patterns × 6
linq × 6
javascript × 5
jquery × 5
performance × 4
sql-server × 4
dependency-injection × 4
controller × 4
asp.net-web-api × 4
authorization × 4
razor × 4
.net × 3
security × 3
api × 3
asp.net-mvc × 3
beginner × 2
html × 2
json × 2
authentication × 2
interface × 2