HV-Lima Peru

Offshore your .NET/SQL Development to Latin America! Languages: en-de-es

Example for Deferred Execution in Linq

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!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: