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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.