开发者

How to do the opposite of eager-loading in Entity Framework?

开发者 https://www.devze.com 2022-12-10 10:02 出处:网络
I understand in Entity Framework you can specify relationships that need to be joined with Include: Product firstProduct =

I understand in Entity Framework you can specify relationships that need to be joined with Include:

Product firstProduct = 
       db.Product.Include("OrderDetail").Include("Supplier").First();

But we have the opposite issue that a simple LINQ statement is getting making too many JOINs on the SQL server.

So how do we do the opposite, i.e. tell Entity to not do any deep lo开发者_运维问答ading of joined tables when it gets all the orders, so that on the SQL Server it executes:

SELECT * FROM Orders


The Entity Framework often goes ahead and loads basic relationship information too.

It does this so users can make updates easily, without violating the EF's unique concurrency policy for relationships.

You can turn this off however by doing a no tracking query.

See Tip 11 - How to avoid relationship span for more information for more information

Alex

0

精彩评论

暂无评论...
验证码 换一张
取 消