How does Change Tracking work in EF Core?

Updated Apr 28, 2026

Short answer

EF Core keeps an Identity Map of queried entities and their original states. When SaveChanges is called, it compares current states to original states to generate SQL.

Deep explanation

When an entity is loaded, it is attached to the context in an 'Unchanged' state. If a property is modified, its state becomes 'Modified'. 'Added' and 'Deleted' states apply to new or removed entities. SaveChanges() scans the ChangeTracker for these states and executes INSERT, UPDATE, or DELETE commands accordingly.

Real-world example

Loading a customer, updating their billing address, and calling SaveChanges() without writing an explicit UPDATE SQL statement.

Common mistakes

  • Assuming untracked entities (e.g., from an API payload) will automatically update the database without explicitly calling Update() or Attach().

Follow-up questions

  • How do you disable change tracking for a query?

More Entity Framework interview questions

View all →