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

Moving Between ObjectContext and DbConte... > Accessing ObjectContext Features fro...

Accessing ObjectContext Features from a DbContext

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.

Note

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:


  

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