SQL Server Interview Question #282
What is change tracking in EF Core?
ASP.NET Core, EF Core & SQL Server Real-World Scenarios Senior Advanced
Detailed Explanation
Change tracking allows EF Core to keep track of entity state such as Added, Modified, Deleted, Unchanged, and Detached. When SaveChanges or SaveChangesAsync is called, EF Core uses tracked state to determine which INSERT, UPDATE, and DELETE commands are required.
Tracking is useful when entities will be modified, but it has memory and CPU cost. For read-only queries, tracking may be unnecessary.
Code Example
var product = await db.Products.FindAsync(id);
product.Price = 99.99m;
await db.SaveChangesAsync();