简体   繁体   中英

DbContext detect lazy loading

I want to move to my entity framework code to .net standard 2.0, however I noticed lazy loading is not supported.

Is there anyway to detect when lazy loading is used in DbContext. That way I can fix those calls before moving to .net standard.

Thanks

Steve

I'm assuming you're using EF 6 since you have not mentioned EF Core.

public class BloggingContext : DbContext
{
    public BloggingContext()
    {
        this.Configuration.LazyLoadingEnabled = false;
    }
}

The above will disable lazy loading on your context. This might be a way forward. I am not suggesting putting this in place and deploying. I am suggesting putting this in place and testing.

Other than that perhaps checking for any "virtual" members on your context entities might help.

The questions comment and the down vote should really indicate that this is not a standard method of checking if you are using lazy loading. The only sure fire way to do that in my opinion is to go through all of your code and check it if the above is of no help.

Also, as mentioned. Lazy loading IS now enabled in EF Core as of 2.1 https://docs.microsoft.com/en-us/ef/core/querying/related-data#lazy-loading

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM