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 ...
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. ...
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 ...
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 ...
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.
<...
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!
...
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 (...
7
votes
Generic ASP.NET MVC controller that generates many pages
This switch should be an if statement instead.
...
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 ...
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 ...
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 (...
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.
...
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) ...
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:
...
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 ...
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 ...
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 <...
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 ...
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 ...
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
...
4
votes
Entity Framework with multiple connections open?
Just a quick note about the way exceptions are handled:
...
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 ...
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 ...
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 ...
4
votes
Accepted
Listing users in Azure Active Directory
Talking about public async Task<ActionResult> Index()
While looking at this
...
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 ...
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
I've also spotted a few things in your code...
This
if (id != null && id.HasValue)
is exactly the same as
...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
asp.net-mvc-4 × 102c# × 96
entity-framework × 26
asp.net × 19
mvc × 8
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