Monday, April 25, 2011

LINQ at a Glance - Part 2

Intepreted Queries
-------------------
Interpreted Queries are descriptive
They operate over sequences that implement IQueryable<> interface.
IQueryable is an extension of IEnumerable with additional methods for constructing Expression Trees.
They resolve to query operators defined in Queryable class.
They emit expression trees that gets interpreted in runtime.
LINQ to SQL and Entity Framework implement IQueryable interface.
Using AsQueryable extension method it is possible to generate IQueryable Wrapper around IEnumerable<> sequence.
Execution of Interpreted Queries
 Interpreted Queries follow a differed execution model.
 Under the covers, interpreted queries differ from local queries in how they execute.
 When you enumerate over an interpreted query, the outermost sequence runs a program that traverses the entire expression tree, processing it as a unit.
 In case of LINQ to SQL, LINQ to SQL translates the expression tree to a SQL statement, which it
 then executes, yielding the results as a sequence.
Compiling Expression Trees - One can convert an expression tree to a delegete using Compile() method.
The AsQueryable operator lets you write whole queries that can run over either local or remote sequences

No comments:

Post a Comment