18 votes

Storing Enum values as Strings in DB

There are clear guidelines for Enum Design where one of them says: X DO NOT use an enum for open sets (such as the operating system version, names of your friends, etc.). and this ...
t3chb0t's user avatar
  • 44.3k
10 votes
Accepted

Joining to in memory List

The dilemmas here: query is an IQueryable. If you join it with offices, i.e. without ...
Gert Arnold's user avatar
  • 2,020
9 votes
Accepted

Cloning Entity Framework entities

Two possible sources of errors: If you forget to use (or don't want to apply) the virtual modifier, it will no longer be a shallow copy (because ...
Gert Arnold's user avatar
  • 2,020
9 votes
Accepted

Improving time it takes to insert thousands of records using Entity Framework

Since you're not making any changes to existing objects, you might set the AutoDetectChangesEnabledproperty of your context to ...
Abbas's user avatar
  • 5,553
9 votes
Accepted

Ordering data by boolean

I wouldn't use either ordering on the server side because it looks like the ordering only matters for displaying the data. I cannot imagine why it should matter from the programmatic point of view. ...
t3chb0t's user avatar
  • 44.3k
9 votes
Accepted

How to optimize for loop with nested foreach

Since you've specifically asked about speeding your code up, I'll answer that first. The main issue you have here is that you're doing a server call for every value in ...
Turksarama's user avatar
8 votes

Improving time it takes to insert thousands of records using Entity Framework

You're doing this for each record: ...
BCdotWEB's user avatar
  • 11.2k
8 votes
Accepted

MVVM - ObservableCollection & Entity Framework DbContext

An EF DbContext is an IDisposable object that should be as short-lived as possible. There are a number of problems with this: <...
Mathieu Guindon's user avatar
7 votes

Service class with db context

You're injecting a disposable resource (context) - this means someone else is creating it (which is excellent BTW), and that someone else should therefore be ...
Mathieu Guindon's user avatar
7 votes

Storing Enum values as Strings in DB

DO NOT USE a raw string and DO NOT USE an enum. Move list to a separate table and add a relation between them. I usually don't like assertions because there are always exceptions. ...
Adriano Repetti's user avatar
6 votes
Accepted

Repository Pattern universal application

What we are looking at is a long tutorial on Inversion of Control and dependency injection. Basically at the most simpilest form you will be looking to abstract your data layer from you application ...
Nico's user avatar
  • 281
6 votes

Entity Framework configuration

My approach is to keep the XxxxxDbContext class as lightweight as possible: ...
BCdotWEB's user avatar
  • 11.2k
6 votes

ASP.NET core proper way to work with the repository pattern

Better? Probably... All your repositories look almost identical, only the served type is different. Therefore, you may as well turn to generic repository. In its elementary form, adopting your ...
Gert Arnold's user avatar
  • 2,020
6 votes
Accepted

Batch save with progress reporting

var count = 0; var lastPercentage = 0d; var nextBatch = new Func<bool>(() => ++count % batchSize == 0); It was a clever usage of context capture but I ...
Bruno Costa's user avatar
  • 5,566
6 votes

Check if the user exists

...
404's user avatar
  • 2,306
6 votes
Accepted

User can add and delete customers

You don't need to enumerate twice here var temp = _context.Users.AsEnumerable().ToList(); You can just call .ToList(). <...
Denis's user avatar
  • 8,458
6 votes

Storing Enum values as Strings in DB

if (Enum.TryParse(billing_location, true, out mbl)) { return (MobiusBillingLocation)Enum.Parse(typeof(MobiusBillingLocation), billing_location, true); } There ...
JanDotNet's user avatar
  • 8,538
5 votes

Data layer using extension methods

One file vs. many partials My first comment is about the ProjectExtensions class itself. I would prefer keeping it together. If for any reason you want to make some ...
Gert Arnold's user avatar
  • 2,020
5 votes
Accepted

Proper way to work with stored procedures in Entity Framework Core

The biggest thing I would change is to return the connection to the state you found it. ...
Der Kommissar's user avatar
5 votes

Scraping HTML via async controller & classes + HTML agility pack

public async Task<ActionResult> UpdateHandicap() We add the Async suffix to methods that are marked with the ...
t3chb0t's user avatar
  • 44.3k
5 votes

Joining to in memory List

Gert Arnold gave a great answer but let me suggest one more soution to try. Yes, data which is got from another source (rather than DB) can be processed in 2 ways: Download as small data part from ...
Tony's user avatar
  • 151
5 votes

Generic repository and generic service

Review Your design uses a dedicated repository and service for each entity. This might look like a great idea at first, but you'll soon realise the drawbacks of this design. Having a service as a ...
dfhwze's user avatar
  • 13.9k
5 votes
Accepted

Repository to update flights

The repository does not need to take responsibility for the errors - remove them from here. The flight repository should add CRUD operations to Flight Dto and not return a result - remove the result. ...
Margus's user avatar
  • 914
5 votes
Accepted

Creating a round robin MySQL connection manager

Aliveness issue As it is, your code does not perform the task you expect it to, because the LoadBalancer never reinstates "dead" connection pools. Notice that you only ever set ...
Vogel612's user avatar
  • 25.2k
4 votes
Accepted

Paginating blog posts from SQL server using nested LINQ statements

Your linq in linq in linq statement is written as a one-liner, with a single semicolon: ...
Mathieu Guindon's user avatar
4 votes
Accepted

Edit one table from another table in a Windows Form DataGridView

As I explain here, you should never initialize reference navigation properties in an entity's constructor. They prevent EF from loading the reference from the database and they impair relationship ...
Gert Arnold's user avatar
  • 2,020
4 votes
Accepted

Domain Model for Simple Yes/No

The idea of creating a Value Object instead of using primitives is to have a highly descriptive domain. Using the second option (the extension method) misses the point. You definitely want to be using ...
RobH's user avatar
  • 16.9k
4 votes
Accepted

API controller with database queries

I see two improvements, one of which Gert Arnold pointed on in a comment. If an API method returns a list, collection or IEnumerable of anything, worse case scenario you should return an empty ...
Greg Burghardt's user avatar
4 votes
Accepted

Take a result set and organize it into a dictionary

Naming The C# standard for publicly-visible properties is to use PascalCase: ...
Dan Lyons's user avatar
  • 3,618
4 votes
Accepted

Calculating the .Sum() in Linq-to-SQL

You have: if (db.BadgeAssignments.Any(bba => bba.UserIdReceiver == newbadgeassignment.UserIdReceiver && bba.BadgeAssociated.CourseId == courseId)) And ...
Mathieu Guindon's user avatar

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