Chapter 5. Change Tracker API

So far you have seen how to use Entity Framework to query for data from the database and save changes to those entities back to the database. You’ve seen how Entity Framework will keep track of any changes you make to entities that are being tracked by a context. It is the responsibility of the Change Tracker to keep track of these changes as you make them.

In this chapter you will learn about using the Change Tracker API to access the information that Entity Framework is storing about the entities it is tracking. This information goes beyond the values stored in the properties of your entities and includes the current state of the entity, the original values from the database, which properties have been modified, and other data. The Change Tracker API also gives you access to additional operations that can be performed on an entity, such as reloading its values from the database to ensure you have the latest data.

You’ve already seen bits of the Change Tracker API in action in earlier chapters. In Chapter 2 you saw how to perform explicit loading using the DbContext.Entry. In Chapter 3 you saw how to get the Change Tracker to scan your entities for changes using the DbContext.ChangeTracker.DetectChanges method. In Chapter 4 you saw how to set the state of an entity, mark individual properties as modified, and work with original values using the Entry method. You also saw how to look at all entities being tracked by the context using the DbContext.ChangeTracker.Entries ...

Get Programming Entity Framework: DbContext now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.