Skip to main content
InterviewHubPRO
Section Overview
Q16

Question 16 of 50

Part 2: Entity Framework Core, Security & High-Performance Data (11 - 24)

32%
ASP.NET Core & Web API (50 Qs)•Part 2: Entity Framework Core, Security & High-Performance Data (11 - 24)

What is the difference between `AsNoTracking()` and Tracking queries in EF Core?

junior LevelCode ExampleFormsPerformanceSecurity & Auth

In Simple Words:

  • Tracking (Default): EF Core's ChangeTracker stores a snapshot of every entity in memory. When you call SaveChangesAsync(), it compares entities against snapshots to generate SQL UPDATE statements.
  • AsNoTracking(): Disables snapshot tracking. Significantly reduces memory allocation and execution time by 30–50%. Must always be used for read-only queries.
csharp
// Read-Only Query (Zero ChangeTracker Overhead):
var users = await context.Users
    .AsNoTracking()
    .Where(u => u.IsActive)
    .ToListAsync(ct);