EntityFrameworkCore 2.1.0 loads all related data by default without using Include

.net asp.net c# entity-framework entity-framework-core

Question

I have a problem with EntityFrameworkCore, it loads all related data by default.

There is no need to post code on this question, it's easy to explain without.

I have a Post class which has a User navigation property. The problem is, that every time I try to load Post, User gets loaded along with it, but I didn't want that. I'm not using lazy loading. I think that lazy loading is not included in EF Core by default, and that you need to reference a special package for it, right? Well, I haven't.

This happens even on most simple queries like the following one:

db.Posts.ToList();

And then, when I try to serialize those posts, I get reference loop handling problem because User again has Posts navigation property on it.

I haven't configured anything in DbContext or Post class related to database.

I am using SQL Server as database, and 2.1.0 provider version.

1
0
6/30/2018 12:33:14 PM

Accepted Answer

I don't know why, but now I see that the problem was that my DbContext was registered as singleton.

Thanks to @IvanStoev

1
6/30/2018 8:06:56 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