EF Core Performance: Tips, Tricks, and Best Practices

EF Core Performance: Tips, Tricks, and Best Practices

3 min read··Updated ·

dotnetef-coreperformance

Slow EF Core queries are rarely EF Core's fault. Most of the time it's a missing projection, an accidental N+1, or change tracking doing work nobody asked for.

This page maps EF Core performance techniques from quick wins to specialized optimizations. Start with query optimization; that's where the biggest gains hide.

Why EF Core Performance Matters

Entity Framework Core is the most popular ORM in the .NET ecosystem. It makes data access simple, but that simplicity can hide inefficient queries, excessive database round trips, and memory issues.

Without proper optimization, EF Core can become the bottleneck in your application - especially under load.

This guide collects the most impactful performance techniques, organized from quick wins to advanced strategies.

Query Optimization

The biggest performance gains usually come from how you write your queries. These articles cover techniques that reduce database load and improve response times.

Choosing Your Data Access

EF Core is not the only way to talk to your database, and it is not always the fastest. These guides help you pick the right tool and get the most out of a lightweight one.

Bulk Operations

When you need to insert or update thousands of rows, the standard SaveChanges() approach won't cut it. These articles show you how to handle bulk data efficiently.

Concurrency and Locking

Concurrent access to the same data can cause race conditions and data corruption. EF Core provides built-in mechanisms to handle this safely.

Advanced Features

EF Core has a rich feature set beyond basic CRUD. These articles cover interceptors, raw SQL, soft deletes, multi-tenancy, and more.

What's New in EF Core 10

EF Core 10 ships with .NET 10 and adds features that used to require workarounds. These articles cover what changed and how to put it to use.

Migrations and Schema Management

Keeping your database schema in sync with your code is a critical part of any EF Core project.

Frequently Asked Questions

What should I optimize first in an EF Core application?

Start by logging the generated SQL and measuring the slow query in the database. Fix N+1 round trips, project only required columns, add indexes for selective predicates, and remove tracking from read-only entity queries before considering lower-level optimizations.

Should every read query use AsNoTracking?

Use AsNoTracking for entity queries that will not be updated through that DbContext. A DTO projection is often better for API reads because it selects only required columns and does not materialize tracked entities in the first place.

Is AsSplitQuery always faster than one joined query?

No. Split queries avoid cartesian duplication when loading several collections, but they add database round trips and may observe changes between statements. Inspect the generated SQL and measure both shapes for the actual graph.

When do compiled EF Core queries help?

They help on hot paths where repeated LINQ compilation is measurable compared with cheap database work. They rarely matter when network and database execution dominate, so benchmark before adding the extra query definition.

Loading comments...

Whenever you're ready, there are 4 ways I can help you:

  1. Pragmatic Clean Architecture: Join 5,000+ students in this comprehensive course that will teach you the system I use to ship production-ready applications using Clean Architecture. Learn how to apply the best practices of modern software architecture.
  2. Modular Monolith Architecture: Join 2,800+ engineers in this in-depth course that will transform the way you build modern systems. You will learn the best practices for applying the Modular Monolith architecture in a real-world scenario.
  3. Pragmatic REST APIs: Join 1,900+ students in this course that will teach you how to build production-ready REST APIs using the latest ASP.NET Core features and best practices. It includes a fully functional UI application that we'll integrate with the REST API.
  4. Patreon Community: Join a community of 5,000+ engineers and software architects. You will also unlock access to the source code I use in my YouTube videos, early access to future videos, and exclusive discounts for my courses.

The .NET Weekly

Become a Better .NET Software Engineer

Join 66,000+ engineers who are improving their skills every Saturday morning.