![]() Before you get excited about that, though, let me put in a caveat: If you are going to work with one entity class's related objects (those objects at the end of a navigation property), then your first choice should be to use the Include keyword/method when retrieving your objects (I discussed why in that article on lazy loading).īut if I'm retrieving Customer objects and only occasionally using the objects in the SalesOrders collection, then I might want to use explicit loading. The other reason I switched is that this code gives me access to the EF DbCollectionEntry object which is a change worth making: I can use DbCollection to speed up my application whenever I use explicit loading. ![]() This might not be something that you worry about. One reason is that using Collection is compatible with EF Core 1.1 and using Reference is not. If you compare this code to what I used in that earlier column, you'll see that I've switched to using the Collection method (my earlier code used a method called Reference). (For a discussion of why I'm using a ToList here, see my tip from earlier this month.) If Not db.Entry(cust).Collection(Function(c) c.SalesOrders).IsLoaded Thenĭb.Entry(cust).Collection(Function(c) c.SalesOrders).Load() That code might look something like this: Dim custs = (From c In db.Customers Issue a line of code to retrieve the related objects if they're not there.Check to see if the navigation property is loaded.Retrieve the object with the navigation property. ![]() With explicit loading, when you want to retrieve the objects at the end of a navigation property, you should do three things: In an earlier column on lazy loading in Entity Framework (EF), I implicitly endorsed "explicit loading" as a preferable alternative to lazy loading.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |