Entity Framework Core 1.0.0 Disable Eager/Lazy Loading

asp.net-core asp.net-web-api2 entity-framework-core json lazy-loading

Question

Can't seem to find any mention of this for EF Core. I've found examples to disable lazy loading in prior EF versions. I have an asp.net core, MVC6, Web Api, and AngularJS site I'm working on.

In the app, I have a table Members and a table MemberStateActions which has a foreign key reference to the Members table. I'm selecting the data using the query below, and then returning the data via Web Api call as Json return type. The resulting MemberStateActions object returned via Web Api has the MemberStateAction.Member object populated. I did not eager load the Member data using .include. I did not lazy load the Member object by calling the property. I don't understand why the Member data is automatically populated. I've read that json serialization maybe be calling the member property causing the lazy loading of the member data before being sent in the Web Api response. Not sure if this is the cause.

Bottom line, I'm looking on some direction as to how to prevent this automatic loading of the member object. Possibly by disabling lazy loading?

        var q = (from x in _context.MemberStateAction
                 where x.MemberId == memberID
                 select x);

        return q;
1
0
7/8/2016 11:28:07 PM

Popular Answer

Entity Framework Core does not have lazy loading implemented at this time (RTM Build).

It is recommended that you do eager loading by using an .Include extension method. It is also a good idea to use a repository to do the eager loading for you.

Reference: https://github.com/aspnet/EntityFramework/issues/3797

0
8/2/2016 3:55:15 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow