Offshore your .NET/SQL Development to Latin America! Languages: en-de-es
Example for Deferred Execution in Linq
April 30, 2010Posted by on
Both examples use the AdventureWorks DB on SQL Server 2008 and the Entity Framework 4.0
1. Deferred Execution
In the first case the query is armed in line 23, but not materialized.
In line 27 result is “Bothell” (see watch on the right side)
Then there is done an update in line 32.
In line 35 the result is Berlin.
This shows clearly, that the execution of the query is deferred to the moment of enlisting.
2. NOT deferred Execution
In this case in the formulation of the query the result is materialized by calling the extension .ToList() in line 43.
Result in line 47 gives back “Bothell” as like Result2 in line 55, despite of having changed the address to Berlin in the meantime!