Reputation: 5225
db.UploadFileSet.Where(f => f.Article.ID == id).ToList();
the ef will load the Article automatically.But I don't need it! How can I stop it?
I know I can write like this:
Select new XXX{Id = xxx ,Name = xxx};
But this is very troublesome.
Upvotes: 1
Views: 5015
Reputation: 364329
The mentioned query will not load related articles. Those articles are loaded when you first access Article
property in your loaded file sets (this includes access by debugger). If you want to ensure that Article
is never lazy loaded you have to turn off lazy loading on your context - you can do that in your code by setting property in context configuration:
db.ContextOptions.LazyLoadingEnabled = false;
db.Configuration.LazyLoadingEnabled = false;
Upvotes: 11