Tutorials Entity Framework Core Tutorial
Change Tracking in EF Core
Change Tracking in EF Core: free step-by-step lesson with examples, common mistakes, and interview tips — part of Entity Framework Core Tutorial on Toolliyo Academy.
On this page
Entity Framework Core Tutorial · Lesson 9 of 100
Change Tracking in EF Core
Beginner → Intermediate → Advanced → Professional
Beginner · 1 — Foundations · ~6 min · Module 1: EF Core Fundamentals
What is this?
EF Core's change tracker watches entities you load or Add. It stores original and current values so SaveChangesAsync can emit precise UPDATE statements for modified columns only.
Why should you care?
When a ShopNest admin edits only Product.Price, EF must UPDATE Price — not rewrite every column blindly.
See it live — copy this example
Paste into a .NET project with EF Core packages, then run with LocalDB/SQL Server (dotnet ef / dotnet run).
var product = await _context.Products.FindAsync(5);
product!.Price = 1499; // tracker marks Price Modified
var entry = _context.Entry(product);
Console.WriteLine(entry.State); // Modified
await _context.SaveChangesAsync();
// UPDATE Products SET Price = @p0 WHERE Id = 5
What happened?
- FindAsync loads and tracks the entity.
- Mutating Price updates the tracker.
- Entry exposes EntityState before save for debugging.
Practice next
- Load one product, change one property, inspect entry.State.
- Compare tracked update vs loading with AsNoTracking then Attach.
- List states: Added, Modified, Deleted, Unchanged, Detached on paper.
- Call entry.Property(p => p.Price).IsModified to see granular flags.
- Use _context.ChangeTracker.Clear() mid-request and observe Detached behavior.
Remember
Change tracker records edits per property. EntityState shows what SaveChanges will do. Tracking has memory cost on large result sets.
ShopNest price update audit
Pricing service loads a tracked Product, changes Price, and SaveChangesAsync writes a single-column UPDATE.
Outcome: Minimal write lock time on hot catalog rows during flash sales.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!