Interface grants access to Object?

Viewed 40

I just started to work with Entity Framework and in order to use ObjectMaterialized and SavingChanges events I have to cast a class which implements DbContext to IObjectContextAdapter interface in this way:

var context = (this as IObjectContextAdapter).ObjectContext;

In the book that I'm reading it says that DbContext does not expose the ObjectContext directly but it implements the IObjectContextAdapter which grants access to that object. My question:How does exactly casting that object to an interface "grants access" to ObjectContext? I looked in the DbContext class and it does not have any ObjectContext object.Also it does not inherit any other object,just implements IObjectContextAdapter interface. So how and from where exactly is the object accessed ?

0 Answers
Related