views:

119

answers:

1

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 loading of joined tables when it gets all the orders, so that on the SQL Server it executes:

SELECT * FROM Orders
+2  A: 

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

Alex James