Skip to main content
7 votes

Preventing duplicate key errors in EF-Core InMemory provider through locking

A lock works here, and it's functional, but it does come with some drawbacks in this case. If you and I both submit the request at the same time, one of them will ...
Der Kommissar's user avatar
6 votes

Using default implementations to superpower flags enums with C#

What are you getting that you couldn't get with properties? ...
RobH's user avatar
  • 16.9k
4 votes

Web-app for tracking containers

EF has zero compatibility with DDD. Any attempt to make your DDD code be suitable for direct EF mapping prevents you from implementing DDD solution – there is no way to do it directly. But any ...
Dmitry Nogin's user avatar
  • 6,131
4 votes

Web-app for tracking containers

I'll answer questions 3 & 4: Is it a good practice to throw an InvalidOperationEception or shall I use some other contract validation framework? I find that ...
t3chb0t's user avatar
  • 44.3k
4 votes

Enum synced with Database

So your Init threw me off, initially I thought this class was doing something, but it was doing something else (not your fault, totally mine). Here's how I would ...
Der Kommissar's user avatar
4 votes

ASP.NET Core 3.1 AddHttpClient call that includes a call to the database

Let me reflect to your other question, which is related to the good old ServicePointManager. In the early versions of .NET Core they tried to get rid of the ...
Peter Csala's user avatar
  • 9,000
4 votes
Accepted

ASP.NET Core 3.1 AddHttpClient call that includes a call to the database

No need to manually create the DbContext. Since you have already registered it with the service collection, resolve it as needed. AddHttpClient has an overload ...
Nkosi's user avatar
  • 3,236
3 votes
Accepted

Entity Framework Core verify SaveChanges count

I can't think of another way of doing this - only the database knows how many rows have been affected. That said, your code has some problems. You need to dispose of your transaction when you're done ...
RobH's user avatar
  • 16.9k
3 votes
Accepted

EF entity, extended with partial classes for actions

The best aspect of your approach is that you keep the autogenerated class as is, which makes it more readable and clean, and keeps your extra code safe from deletion if you modify the database schema. ...
modeeb's user avatar
  • 156
3 votes
Accepted

Web-app for tracking containers

First of all, congratulations with your efforts to apply DDD principles and finding Evans's excellent book. You're on the right track. Just a couple of comments: What is the convention for placing ...
Gert Arnold's user avatar
  • 2,020
3 votes
Accepted

Bank ATM Mockup App

Domain Model layer Your domain classes serve 3 conflicting purposes: Data Transfer Object ORM Object (Data Record for EF, some call this a DAO, others wouldn't) Business Entity For bigger projects, ...
dfhwze's user avatar
  • 13.9k
3 votes
Accepted

Asynchronous IBAN API with validation

I'm not very experienced with EF, to me your code looks fine but there are some details you can improve as stated in the other answer, and of course other ways of writing the same which I will show ...
Gus's user avatar
  • 216
3 votes

Get a list of the 25 most popular items on an E-Commerce site

When ToList is called, the IQueryable will be executed at DBMS, and store the results in the memory. So, if there is more data ...
iSR5's user avatar
  • 5,248
3 votes
Accepted

EFCore Monitor Interceptor with logging queries

CommandFailed I would suggest to check whether the eventData is not null as well, not just ...
Peter Csala's user avatar
  • 9,000
2 votes

Retrieving the IDs of entries to be deleted from a table

If you weren't using EntityFrameworkCore, my suggestion would look something like this: Get the list of values from database 1 Use SqlBulkCopy to insert a bunch of ...
Dan Oberlam's user avatar
  • 7,804
2 votes

Handling Entity Framework in connected mode within Windows Forms

It is a best-practice to have a clear separation between UI layer (the forms) and data access, so all your data access logic (opening the connection, issuing quries, closing it etc.) should be handled ...
Alexei's user avatar
  • 1,816
2 votes

Is it fine to use my domain model as DTO (Entity Framework Core)?

As I explain here, the EF model is primarily a data layer. Its classes may be suited for other roles, but their primary responsibility should always be: smooth data access. Your question is about ...
Gert Arnold's user avatar
  • 2,020
2 votes
Accepted

Is it fine to use my domain model as DTO (Entity Framework Core)?

I was reading about anemic data models and rich domain models in DDD. I don't want to follow DDD completely but take rather pragmatic approach and just take some concepts out of it because clean ddd ...
Flater's user avatar
  • 5,542
2 votes
Accepted

EF Core Complex Query Method

As mentioned in a comment of mine, it's possible that there's a bug in the code. The ...
Gentian Kasa's user avatar
  • 2,046
2 votes
Accepted

Applying EF core in Universal Windows Apps using a large database

In this tutorial, it shows the usage of a dbcontext derived class inside a function called Page_Loaded in MainPage.xaml.cs. Is this a bad design? Yes, I think it is a bad design and implementing a ...
t3chb0t's user avatar
  • 44.3k
2 votes
Accepted

Web Service that gets data from multiple tables in a database using EF Core Database-First approach

Controllers should be kept as lean as possible. Consider adding another layer of abstraction specific the controller in order to separate concerns. ...
Nkosi's user avatar
  • 3,236
2 votes
Accepted

Configuring certificate signing for development and production environments

There is a lot of repeated code in the if and the else branch which can be extracted. Assuming the ...
Heslacher's user avatar
  • 50.4k
2 votes

Entity Framework Core verify SaveChanges count

No need to do this at all. For one, Entity Framework keeps track of expected changes itself, probably better than you can do it. It is expected that the developer should know how many records will be ...
Gert Arnold's user avatar
  • 2,020
2 votes

Three-way join in Entity Framework Core to retrieve all roles that a user has

For this isolated piece of code, this is the way to go. Generally, in ORMs that support LINQ, navigation properties (like ur.Roles) should be used wherever possible....
Gert Arnold's user avatar
  • 2,020
2 votes
Accepted

ASP.NET EF seed one to many relation

By default, Entity Framework will create the foreign key with the name of the entity primary key that is referenced by the navigation property. ...
iSR5's user avatar
  • 5,248
2 votes
Accepted

Prepare and export data to MS Word file

My observations... Leave generated classes alone You have modified Contracts by adding a custom constructor to it. You'll loose this changes when you regenerate ...
t3chb0t's user avatar
  • 44.3k
2 votes
Accepted

A simple method to execute Entity Framework Core queries in parallel

All public API surfaces should validate input parameters. Restricting the queries to a single entity type seems limiting. You can't join entities with no navigation properties. It fails when using ...
Johnbot's user avatar
  • 2,974

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