Interview frequency: …
Short answer
The Change Tracker keeps object snapshots in memory to detect changes and persist them with SaveChanges(); AsNoTracking disables this tracking, saving memory and significantly speeding up read queries.
Explanation
For an ordinary EF Core query, the engine creates an object and stores an original Snapshot in the DbContext to track changes to its properties. Read-only queries, such as display pages and APIs, do not need updates saved. Using .AsNoTracking() avoids creating tracking snapshots, reducing RAM use and query time (depending on result size).
Code example
// Ultra-fast read query without change-tracking allocations
var users = await dbContext.Users
.AsNoTracking()
.Where(u => u.IsActive)
.ToListAsync();Common mistakes
- Calling AsNoTracking() on an object you want to modify, then wondering why SaveChangesAsync() does not persist the changes.
Follow-up questions
- How do ExecuteUpdate and ExecuteDelete in EF Core 7+ improve performance for bulk operations?
- Why is DbContext not thread-safe, and what does DbContext Pooling do?