Entity Framework Core Interview Question #17

What is change tracking in EF Core?

EF Core Fundamentals & DbContext Junior Beginner

Quick Interview Answer

Change tracking is the mechanism EF Core uses to remember entity instances and their states so it can determine what database commands are required when SaveChanges is called.

Detailed Explanation

Change tracking is the mechanism EF Core uses to remember entity instances and their states so it can determine what database commands are required when SaveChanges is called.

Tracked entities can be Unchanged, Added, Modified, Deleted, or Detached. EF Core compares tracked state and property information to generate appropriate INSERT, UPDATE, or DELETE operations.

Tracking is useful for update workflows but adds memory and processing overhead, so read-only queries often benefit from AsNoTracking.

Code Example

var product = await db.Products.FindAsync(id);

product!.Name = "Updated Name";

await db.SaveChangesAsync();
// EF Core detects the modification and issues UPDATE.