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 a singleton value or a sequence of values. Those methods that return a singleton 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.
In the case of the methods that operate on in-memory collections, that is, those methods that extend IEnumerable<(Of <(T>)>)
, the returned enumerable object captures all of the arguments that were passed to the method. When that object is enumerated the logic of the query operator is employed and the query results are returned.
In contrast, methods that extend IQueryable<(Of <(T>)>)
do not implement any querying...