Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

3. Adding, Changing, and Deleting Entities > Working with Change Tracking

Working with Change Tracking

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.

Snapshot change tracking

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.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial