views:

48

answers:

2

Hi, I am new to the entity framework and wondered, when the data is actually taken from the database. If I e.g. does:

from order in orderQuery where order select car;

is the data then selected from the database, or is it first when I manipulate it like the code below?

(from order in orderQuery where order select car).ToList();
+1  A: 

The entity framework works in lazy-load fashion, the databse is queried only when the data is actually needed.

So the query will only be executed on your second example.

Paulo Santos
+1  A: 

LINQ queries have a property called delayed execution. This separates out the building and execution of a query into 2 distinct parts. The first example you gave only defines a query and hence won't cause any execution. The second however will force the query to run to completion

JaredPar