Technology

Entity Framework: A Great Default, If You Know Where It Bites

18 Nov 2026

I asked Gemini for the pros and cons of Entity Framework Core, and its answer was more sensible than I expected. Here's my version: what EF is good at, where it hurts, two places where the usual advice is out of date, and the setup most .NET teams end up with anyway.

What EF Core is good at

Entity Framework Core is Microsoft's ORM for .NET, and it's the default for a reason:

  • Writes are easy. Load some entities, change them, call SaveChanges(). EF works out what changed and sends the INSERTs, UPDATEs and DELETEs, batched into as few round trips as it can.
  • Migrations are built in. The schema lives next to your C# model and evolves with it, in source control. (EF Core 11, out last week, even records the latest migration in the model snapshot, so two developers adding migrations on different branches get a merge conflict instead of a silent mess.)
  • Refactoring is safe. Queries are C#. Rename a property and the compiler finds every query that used it. With SQL in strings, you find out at runtime.
  • Databases are swappable. SQL Server in production, SQLite in tests, PostgreSQL for the next project: mostly a different provider package.

Where it bites

Almost all of the problems come from the same place: LINQ hides the SQL, so it's easy to write C# that looks innocent and generates something terrible.

  • N+1 queries. Loop over 100 orders, touch order.Customer inside the loop, and you may get 101 database round trips instead of one.
  • Cartesian explosion. Include two large collections in one query and the result set multiplies: every comment repeated for every tag. AsSplitQuery() fixes it, but you have to know to ask.
  • Tracking everything. By default EF keeps a copy of every entity it loads so it can detect changes later. On read-only pages that's wasted memory and CPU. The best fix is often to load less:
// Loads whole entities, with all their comments, and tracks every one:
var posts = await db.Posts.Include(p => p.Comments).ToListAsync();

// Reads only what the page shows; projections like this aren't tracked at all:
var rows = await db.Posts
    .Select(p => new PostRow(p.Title, p.Comments.Count))
    .ToListAsync();
  • Bulk work. Pushing tens of thousands of rows through the change tracker is slow and memory-hungry. ExecuteUpdate and ExecuteDelete (since EF Core 7) handle set-based changes, but there's still no built-in upsert, and EF Core 11 doesn't add one either. Bulk inserts and upserts mean raw SQL, SqlBulkCopy or a third-party extension.
  • LINQ that doesn't translate. Call a C# method EF can't turn into SQL and the query fails at runtime, not compile time.
  • DbContext isn't thread-safe. Two parallel queries on one context will eventually throw. Background workers need their own context.

Two pieces of advice that have aged

"Contains on a large list hits SQL Server's 2,100-parameter limit." This one depends on your version. Up to EF Core 7, the list values were written into the SQL as constants. EF Core 8 and 9 sent the whole list as a single JSON parameter, so the limit didn't apply. EF Core 10 went back to one parameter per value by default (it gives the database's query planner better information), so with a list of thousands of IDs it's worth checking the SQL your version actually generates. Since EF Core 9, you can choose the strategy yourself, globally or per query.

"Running Database.Migrate() at startup causes races when several instances start at once." Since EF Core 9, EF takes a database lock while it applies migrations, so two instances can't run them simultaneously. Microsoft still recommends applying migrations as a deployment step rather than at startup, and I agree: a slow migration shouldn't be what decides whether your app passes its health check.

When I'd reach for something else

  • Reporting and analytics. Window functions, CTEs, recursive queries: all awkward or impossible in LINQ, and easy in SQL.
  • Bulk loads and ETL. Use SqlBulkCopy or PostgreSQL's COPY, not the change tracker.
  • Legacy databases built around stored procedures, triggers and naming conventions EF doesn't share.
  • Hot read paths where every allocation counts. A micro-ORM like Dapper maps rows straight to objects with very little overhead.

The setup most teams end up with

This isn't really a choice between EF and Dapper. Both sit on top of the same ADO.NET connection, so they work side by side in one project: EF for writes and migrations, plain SQL through Dapper for the read-heavy and reporting queries. They can even share a transaction:

await using var tx = await db.Database.BeginTransactionAsync();
db.Orders.Add(order);
await db.SaveChangesAsync();

var totals = await db.Database.GetDbConnection().QueryAsync<DailyTotal>(
    "SELECT ... FROM Orders ...", transaction: tx.GetDbTransaction());

await tx.CommitAsync();

The view from the Rust side

This site is written in Rust, and its database code is the Dapper approach: plain SQL strings with values bound in, through sqlx. sqlx can check queries against the real database at compile time, but that needs a live database just to build, so I went without. The cost is exactly the one Gemini points out for Dapper: a typo in a column name shows up when the query runs, not when the code compiles. On a small project that's a fine trade. On a large codebase with many developers, EF's refactoring safety is worth a lot.

Verdict

EF Core is a good default for ordinary business applications, and I'd start a new .NET project with it. Just learn what SQL your queries turn into (turn on query logging in development and read it), keep reads lean, and don't be religious about it: when a query is easier in SQL, write SQL.

Sources: What's new in EF Core 9, EF Core 10, EF Core 11, and a conversation with Gemini.

Comments

No comments yet.

Log in to leave a comment.