I need to load the navigation property of an entity. I've been reading a great article on different approaches how to load navigation properties with Entity Framework (6.0).
The second way to explicitly Load is from the ObjectContext, rather than from EntityCollection or EntityReference. If you’re relying on POCO support in the Entity Framework, your navigation properties won’t be EntityCollections or EntityReferences, and therefore won’t have the Load method. Instead, you can use the ObjectContext.LoadProperty method. LoadProperty uses generics to identify the type that you’re loading from and then a lambda expression to specify which navigation property to load. Here’s an example of using LoadProperty to retrieve the Pets for a particular person instance:
context.LoadProperty<Family>(familyInstance, f => f.Pets)
Now the only thing I need to know:
How do I get a reference to the ObjectContext?
DbContext
does not seem to derive from it, nor does it hold a reference to it. The LoadProperty<T>
is not static, so I do need an object reference.