Linq to Entities - Eager Loading?

You aren't really. Linq loads the objects as you need them, but it does it tranparently so as soon as you start to browse the objects (either in code or in a debugger watch) it loads them so it looks as though you have them all there already If you perform the query and then kill the connection to the database you will get database exceptions when you try and browse the objects as it will be unable to load them Edit: Sorry, I Misread the question. Linq-to-entities does not support lazy loading (See comment from Craig below).

To get the full object graph you should either use "Include" in the Linq query or call Load() on each reference. Sorry, I cannot explain the behaviour described in the question. Can you give some more detail.

Perhaps post your query and code.

You aren't really. Linq loads the objects as you need them, but it does it tranparently so as soon as you start to browse the objects (either in code or in a debugger watch) it loads them so it looks as though you have them all there already. If you perform the query and then kill the connection to the database you will get database exceptions when you try and browse the objects as it will be unable to load them.

Edit: Sorry, I Misread the question. Linq-to-entities does not support lazy loading (See comment from Craig below). To get the full object graph you should either use "Include" in the Linq query or call Load() on each reference.

Sorry, I cannot explain the behaviour described in the question. Can you give some more detail. Perhaps post your query and code.

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 Sep 17 '09 at 14:13 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 Sep 17 '09 at 14:51 In fairness, it's hard to say why a query behaves the way it does without seeing the query. :) – Craig Stuntz Sep 17 '09 at 15:53.

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.

Which will eager load the answers of all questions. So even though it looks like I'm only pulling the answers for the first question, I'm actually pulling all the answers for all the questions.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions