O'Reilly logo

WCF Multi-layer Services Development with Entity Framework Fourth Edition by Mike Liu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deferred execution

One important thing to remember when working with LINQ to Entities is the deferred execution of LINQ.

Standard query operators differ in the timing of their execution depending on whether they return an aggregation value or a sequence of values. Those methods that return an aggregation value (for example, Average and Sum) execute immediately. Methods that return a sequence defer the query execution and return an enumerable object. These methods do not consume the target data until the query object is enumerated. This is known as deferred execution.

Checking deferred execution with SQL Profiler

To test the deferred execution of LINQ to Entities, let's first add the following method to our Program.cs file:

 static void TestDeferredExecution() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required