views:

148

answers:

2

I have a complex object and when I use a linq query without the Include syntax, I am still getting all the related entities back in my object graph. Wha can explain this?

+1  A: 
Simon P Stevens
This answer reads as though LINQ to Entities was doing lazy loading. Perhaps that is not what was intended, but that's how I read the text here. In fact, LINQ to Entities does not do lazy loading (unless you are using version 4 and specifically enable it). It's hard to say more without seeing the actual query.
Craig Stuntz
Ahh. Good point, I just saw Linq and thought Linq-to-SQL (Which works as described in my answer). Yes, you are right Craig, Linq to Entities does not do Lazy loading. You either have to use "Include" or call Load() on the references. In this case I cannot explain the behaviour described in the Question.
Simon P Stevens
In fairness, it's hard to say why a query behaves the way it does without seeing the query. :)
Craig Stuntz
A: 

Perhaps you are using Entity Framework 4 and lazy lading is enabled. You can check the ObjectContextOptions.LazyLoadingEnabled property on your context. Although the property is 'false' by default, the model generation tools normally set it to 'true'. Check the MSDN article on Loading Related Objects - the section on lazy loading explains this.

Govert