Expression Trees for Query Expressions

To turn entire query expressions into some kind of remote execution, the first trick that has to be played by the LINQ providers is to get their hands on an expression tree with all the required information about the querying intent. Because you now know about the origin of expression trees, it should come as no surprise that the function arguments to a variety of query operators need to be turned into Expression<TDelegate> ones.

If we were to rewrite our hypothetical Table<T> (and Query<T>) as shown here, query expressions over the objects would trigger the generation of expression trees.

class Table<T>{    public Query<T> Where(Expression<Func<T, bool>> predicate) { ... } ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.