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

BeginnerIntermediateAdvancedProfessional

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

  1. Load one product, change one property, inspect entry.State.
  2. Compare tracked update vs loading with AsNoTracking then Attach.
  3. List states: Added, Modified, Deleted, Unchanged, Detached on paper.
  4. Call entry.Property(p => p.Price).IsModified to see granular flags.
  5. 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.

Junior PDF Detailed
What is change tracking in EF Core?
Short answer: fter they are loaded from the database. This allows EF Core to generate the correct SQL INSERT, UPDATE, or DELETE statements when SaveChanges() is called. Real-world example (ShopNest) Read-only catalog pag…
Junior PDF Detailed
What is change tracking in EF Core?
Short answer: Change tracking is the process by which EF Core keeps track of changes made to entities after they are loaded from the database. This allows EF Core to generate the correct SQL INSERT, UPDATE, or DELETE sta…
Mid PDF Detailed
How to disable change tracking globally?
Short answer: You can disable tracking by default for a specific DbContext using: optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTrac king); Or per-query using .AsNoTracking(). Real-world example (ShopNe…
Mid PDF Detailed
How does Code First handle schema changes in the database?
Short answer: EF Core uses migrations to track and apply schema changes: You modify your C# models. Use Add-Migration to create a migration class. Use Update-Database to apply the changes to the DB. EF Core compares the…
Mid PDF Detailed
How do you handle conflicts in migrations (e.g. when team members make schema changes)?
Short answer: Best practices: Communicate and coordinate migration changes. Always pull and apply the latest migrations before adding a new one. If conflicts arise: Resolve merge conflicts in migration files manually. Re…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Entity Framework Core Tutorial
Course syllabus

Entity Framework Core Tutorial

Module 1: EF Core Fundamentals
Module 2: Code First Approach
Module 3: CRUD Operations
Module 4: LINQ
Module 5: Relationships
Module 6: Advanced EF Core
Module 7: Performance Optimization
Module 8: Enterprise Architecture
Module 9: Testing & Debugging
Module 10: Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details