When to Skip Entity Framework Core Tracking for Read-Only Queries
Learn why Entity Framework Core’s change tracker adds hidden overhead on read-only queries and how AsNoTracking removes it — plus the trade-offs you must consider before applying it everywhere.
29 May 2026, 21:09 UTC

The problem: hidden work on a read-only endpoint
An API endpoint that returns a list of active customers often looks like this:
var customers = await db.Customers
.Where(c => c.IsActive)
.OrderBy(c => c.Name)
.Take(50)
.ToListAsync();
Even though the caller never mutates the returned objects, EF Core still creates an entry in its change tracker for every entity. That means an identity-map lookup, a snapshot of original values, and a later change-detection pass - all work that will never be used.
Thesis: opt out of tracking on clearly read-only paths
Explicitly calling AsNoTracking() tells EF Core to materialize the entities without adding them to the tracker. The query still runs the same SQL, but the runtime bookkeeping disappears. Keep tracked queries for any code that later updates or relies on navigation fix-up.
What tracking actually does
- Identity map - ensures the same CLR instance is returned for a given primary key within the same
DbContext. - Original-value snapshot - stores a copy of each property so EF Core can later compute what changed.
- Relationship fix-up - wires navigation properties between tracked entities automatically.
When the application only reads data, none of these services are needed. The overhead is modest per entity but adds up with large result sets or high-frequency endpoints.
Worked example: a read-only list endpoint
Assume a typical ASP.NET Core minimal API using EF Core 8.0 (behavior is the same in 9.0). The endpoint returns a DTO, but the query needs the full Customer entity because the projection is built in memory.
app.MapGet("/api/customers/active", async (AppDbContext db) =>
{
var customers = await db.Customers
.AsNoTracking()
.Where(c => c.IsActive)
.OrderBy(c => c.Name)
.Take(50)
.ToListAsync();
var dtos = customers.Select(c => new CustomerDto(c.Id, c.Name, c.Email));
return Results.Ok(dtos);
});
If the projection were done in the query (.Select(c => new CustomerDto(...))), EF Core would never materialize tracked entities, making AsNoTracking() redundant. The method matters most when you need the entity instance itself - for example, when passing it to a serializer that expects the full type.
Trade-offs and when not to use it
- No change detection - modifications to the returned objects are invisible to
SaveChangesAsync(). - No identity-map reuse - two identical queries will produce distinct object graphs.
- No navigation fix-up - related entities loaded via
Includeare not automatically linked to each other.
Do not apply AsNoTracking() when the same context later updates those entities, or when business logic depends on navigation properties being populated across the graph. In those cases either keep the query tracked or detach-attach explicitly:
var tracked = await db.Customers.FindAsync(id);
tracked.Name = "New";
await db.SaveChangesAsync();
Measuring the impact in your project
Run a quick benchmark against a realistic data set to see if the optimization matters:
- Create a console project referencing your
DbContextand the BenchmarkDotNet NuGet package. - Add two methods - one with
AsNoTracking(), one without - that execute the same query. - Run
dotnet run -c Releasefrom the project directory (requires .NET SDK, no elevated permissions). - Compare the
MeanandAllocated Memorycolumns; a reduction of 10-30% in allocation is typical for large graphs.
Enable EF Core logging (Microsoft.EntityFrameworkCore.Database.Command at Information) to verify the generated SQL is identical in both cases. If the query plan changes, the difference is likely due to query shape, not tracking.
Actionable closing
Treat AsNoTracking() as an intentional architectural decision, not a default. Document the endpoints that use it, and add a regression test that asserts the endpoint returns correct data while a parallel update test confirms tracked workflows still persist changes. Re-run the benchmark after major EF Core upgrades (for example, 8 to 9) because default tracking behavior can shift.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.