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 ...
brainless coder's user avatar
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 (...
Zohar Peled's user avatar
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: ...
zaitsman's user avatar
  • 161
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. ...
user1533613's user avatar
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 ...
t3chb0t's user avatar
  • 44.2k
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 ...
BCdotWEB's user avatar
  • 11.2k
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 ...
Heslacher's user avatar
  • 50.3k
3 votes

Recording error messages from an exception

You can use GetBaseException to get the lowest level exception. ...
Mike Norgate's user avatar
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 ...
Mathieu Guindon's user avatar
2 votes

DbSet<T> IncludeAll method

Include uses when you want to include ICollection properties or not int, string, ...
Islam Alshiki's user avatar
2 votes
Accepted

Passing model to _layout.cshtml

Implemented a better design by converting the navigation section into a PartialView and converted UserViewModelBase and ...
niklodeon's user avatar
  • 193
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 ...
xDaevax's user avatar
  • 1,171
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 ...
iSR5's user avatar
  • 5,138
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 ...
Adriano Repetti's user avatar
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 ...
Hekku2's user avatar
  • 161
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 ...
Geek's user avatar
  • 439
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 ...
RubberDuck's user avatar
  • 30.8k
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 ...
Ewan's user avatar
  • 661
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 ...
user1715749's user avatar
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 ...
Dejan's user avatar
  • 143

Only top scored, non community-wiki answers of a minimum length are eligible