Efcore: Explicit loading support

Created on 4 Sep 2014  路  7Comments  路  Source: dotnet/efcore

Explicitly triggering the loading of associated data through a navigation can be handy especially when loading across aggregate bondaries or when working with stores that are not natively aggregate oriented. In previous versions of EF we had such methods as Load() and LoadAsync() on reference and collection property entries. We also had handy Query() methods that returned the query we would use to load the data so that filters could be composed over them before executing them. We should have the equivalent functionality in EF7.

closed-fixed type-enhancement

All 7 comments

+1; I've recently been porting some old EF6 code which used lazy loading and while I'm ok with not using lazy loading in the new world, some of the models are too large to entirely eagerly load. Instead, I have to explicitly load related objects as they're needed. Having first-class support for this with APIs like Load() and LoadAsync() would make porting easier.

+1 for this

The docs here reference this issue.
if u close this it means the issue solved? if so - can u fix the docs? thanks!

@arielcloud it's fixed in our working code base, but not in the current stable release. We will update the docs when this is released in 1.1.

Looking at this it occurs to me that it would be nice to have a model attribute that would allow you to specify that related entities or collections should always be included. This would greatly mitigate the need for lazy or even explicit loading in many situations.

It'd be nice if you could just say:

public class Album
{
    ...
    [Include]
    public Artist Artist {get; set;}

    [Include]
    public Track[] Tracks {get; set; }
}

@RickStrahl I think that is covered by #1985, but please let us know if you have additional feedback.

Thank you. Yup that looks like it would work.

These options will make life a lot easier for generic code in base repositories.

Was this page helpful?
0 / 5 - 0 ratings