Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Throughout this chapter you have seen that Entity Framework keeps
track of the changes you make to your objects. Entity Framework uses its
change tracker to do this. You can access the change
tracker information, and some change tracking–related operations, through
the DbContext.ChangeTracker property.
You’ll see more about the Change Tracker API in Chapter 5.
There are two different ways that Entity Framework can track the changes to your objects: snapshot change tracking or change tracking proxies.
The code written so far in this chapter has relied on snapshot
change tracking. The classes in our model are all POCO and they
don’t contain any logic to notify Entity Framework when a property
value is changed. Because there is no way to be notified when a
property value changes, Entity Framework will take a snapshot of the
values in each property when it first sees an object and store the
values in memory. This snapshot occurs when the object is returned
from a query or when we add it to a DbSet. When Entity Framework needs to know
what changes have been made, it will scan each object and compare
its current values to the snapshot. This process of scanning each
object is triggered through a method of ChangeTracker called DetectChanges.