O'Reilly logo

Fluent Entity Framework by Rebecca M. Riordan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving state entities

Of course, before we can work with the state metadata, we need to obtain a reference to the object that represents it. Both the ObjectContext and DbContext expose methods to retrieve the state entry for a specific entity or a collection of entries:

To retrieve the state entry for a specific entity, you use the ObjectStateManager.GetObjectStateEntry() method in the ObjectContext API, or the Entry() method of the DbContext:

Image

The ObjectContext provides an ObjectStateManager.GetObjectStateEntries() method that retrieves all the entries by their state. To filter the results by entity type or set, you can use LINQ operators ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required