Entity Framework Core Interview Question #103
What is the EF Core ChangeTracker?
Change Tracking, Updates, Transactions & Concurrency Mid-Level Intermediate
Quick Interview Answer
ChangeTracker provides access to information and operations for entities currently tracked by a DbContext. It can inspect entries, entity states, original/current values, tracked relationships, and change-detection behavior.
Detailed Explanation
ChangeTracker provides access to information and operations for entities currently tracked by a DbContext. It can inspect entries, entity states, original/current values, tracked relationships, and change-detection behavior.
It is useful for diagnostics, auditing, custom persistence workflows, and understanding what SaveChanges will process.
Business logic should generally not manipulate the change tracker unnecessarily; use it when persistence-level control is actually required.
Code Example
foreach (var entry in db.ChangeTracker.Entries())
{
Console.WriteLine(
$"{entry.Entity.GetType().Name}: {entry.State}");
}