Scarass
Scarass

Reputation: 944

EntityFrameworkCore 2.1.0 loads all related data by default without using Include

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.

Upvotes: 0

Views: 624

Answers (1)

Scarass
Scarass

Reputation: 944

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

Thanks to @IvanStoev

Upvotes: 1

Related Questions