Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
If you are starting with a DbContext, you can access the ObjectContext features very easily through the
IObjectContextAdapter. In fact,
you’ve seen this done a few times in this book already. In Chapter 4 we used this to
access the ObjectMaterialized event
that is not available directly on DbContext.
The Entity Framework team refers to the procedure of accessing
the ObjectContext from DbContext as “dropping down to ObjectContext.” You have seen this
expression used a few times already in this book.
The pattern to get to the ObjectContext is to cast the DbContext instance to this IObjectContextAdapter and, from there, access
its ObjectContext property. DbContext is implemented as an explicit
interface of IObjectContextAdapter,
which is why you need to explicitly cast it: