Change Tracking
Learn the basics about change tracking in EF Core.
Overview
In this lesson, we’ll learn how EF Core tracks the changes we make to entities. Each DbContext
instance tracks changes through the ChangeTracker
. The ChangeTracker
resides in the Microsoft.EntityFrameworkCore.ChangeTracking
namespace and tracks the state of every entity instance retrieved with the same DbContext
instance.
The projects in this lesson include data from the table below:
Employees
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
Albums
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Note: The projects in this lesson make calls to
ChangeTracker.DebugView.LongView
. This allows us to obtain a human-readable view of the state of the tracked entities at a specific point in time.
Tracking entities
Entity instances become tracked when they are:
- Returned from a query executed against the database.
- Explicitly attached to the
DbContext
byAdd
,Attach
,Update
, or similar methods. - Detected as new entities connected to existing tracked entities.
EF Core stops tracking entity ...
Get hands-on with 1400+ tech skills courses.