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 ...
user avatar
10 votes
Accepted

Tracking sports statistics

Don't use underscores in identifiers. If that's how the database has them, use a ColumnAttribute to specify the column name scratch that, you're going code-first. ...
user avatar
10 votes
Accepted

Onion Architecture

Let me know if I went wrong somewhere. This is the first time I set up an application with a proper architecture. I'm afraid there is no such thing as general "proper" architecture. Relevant ...
user avatar
  • 7,132
9 votes

Tracking sports statistics

I made a small example to show you that all your worries are in the past. Before you implement this yourself though, keep Mat's remarks in mind: I made this as a quick sketch and separating the ...
user avatar
8 votes

Truncate port number from absolute Uri

I have witnessed the UriBuilder .port = -1 fix elsewhere. Frankly guys, it is a hack that really isn't a good production ready solution. The right solution here is to use UriBuilder as follows. <...
user avatar
8 votes

Configure AspNet.Identity to allow for either username OR email address on login

I added some formatting to that nested ternery to try to understand what it's doing, and it still took me a while! ...
user avatar
  • 5,714
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 (...
user avatar
7 votes

Generic ASP.NET MVC controller that generates many pages

This switch should be an if statement instead. ...
user avatar
  • 28.5k
7 votes

Multi-checkbox validation

I'll answer your second question first! The fact that one of your your checkboxes needs to be checked is a validation that is more about your class than one of your checkbox. I mean, individually, a ...
user avatar
  • 12.2k
7 votes
Accepted

Return existing values inside database

First of all, get rid of this line: JsonResult json = new JsonResult(); Just use return new JSON(...). Now, you have ...
user avatar
  • 315
6 votes

Tracking sports statistics

I suggest to use the same name for primary and foreign keys following some consistent pattern: It could be e.g. _id or Id, so you will have in PlayerAccount table the primary key PlayerAccountId (...
user avatar
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. ...
user avatar
6 votes
Accepted

Setting new lines and adding them to a list to be drawn

Do you know about radians? Math.Cos (and the other trig functions in .Net) are based on radians not degrees. Math.Cos(90) ...
user avatar
  • 16.6k
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: ...
user avatar
  • 161
5 votes
Accepted

Injecting AutoMapper profiles

What is the purpose of the IMapper interface and Mapper class? It looks to me that they are just wrapping the ...
user avatar
5 votes

Accessing server side variables in views and JavaScript

Yes, that is how I would typically do it. As an alternative concept which I also like to consider at times is using JavascriptSerializer to convert a list to an ...
user avatar
  • 6,407
5 votes

Accessing server side variables in views and JavaScript

This is how I see server variables and local variables interacting. There is not really any other way to get the values between the two that I'm aware of. As for the code, I one minor point:change <...
user avatar
5 votes

Confusion over using generics in MVC project

First of all, I appreciate the fact that you want to keep your code DRY as many developers are not concerned with this. Also, I like the idea of having the generic ...
user avatar
  • 1,171
5 votes

Setting new lines and adding them to a list to be drawn

I would say that Heslacher's idea to use a copy constructor is a good direction, but that has two arguments, doesn't have a descriptive name, and violates the Do one thing principle as it copies a ...
user avatar
  • 51
5 votes
Accepted

N-tiered web app to save a role

Naming conventions. In C#, types are named using PascalCase. Rename: OM_Role to OmRole ...
user avatar
  • 1,167
4 votes

Entity Framework with multiple connections open?

Just a quick note about the way exceptions are handled: ...
user avatar
4 votes
Accepted

Class to Return Single Integer

I see a number of things wrong with this implementation: First, You already have a CommuteData entity. Why are you using it to go back to the database to retrieve ...
user avatar
  • 1,873
4 votes

ASP.NET MVC return early from an action that returns a model

I will review the first method. Code duplication I see 3 times checking for dataRetrieveModel.LineList.Count > 0 and 2 times checking for ...
user avatar
  • 49.9k
4 votes
Accepted

Admin class for monitoring blog users

The UpdateBlogPost and SaveBlogPost methods are identical (unless I missed something). Not sure if this is a bug or intended ...
user avatar
  • 20k
4 votes
Accepted

Listing users in Azure Active Directory

Talking about public async Task<ActionResult> Index() While looking at this ...
user avatar
  • 49.9k
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 ...
user avatar
  • 49.9k
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 ...
user avatar
  • 10.6k
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 ...
user avatar
  • 43.8k
3 votes
Accepted

Calculating total sales from each member

I won't comment about the fact that this is a static method in what's possibly a static "helper" class and that it ...
user avatar
3 votes
Accepted

Model Design for MVC4 Applications using Entity Framework Code First

I've used this kind of approach myself in the past and it's worked well. However lately I've been considering whether it's overkill. Considering Entity framework is already following the repository ...
user avatar
  • 6,407

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