LINQ and Expression Trees
Expression Trees represent code in a tree-like data structure. In LINQ, expression trees represent structured queries that target sources of data that implement IQueryable<T>. For example, LINQ to SQL provider implements the IQueryable<T> interface, wherein during run-time, when a LINQ to SQL query is executed the underlying implementation leverages the Expression Tree to convert the LINQ query to a “tree like data structure” and then constructs the required output (which in this case is the SQL query), i.e., translate it into a query language appropriate for the data source. However, on the contrary, when we use LINQ queries to filter data from objects, it returns an IEnumerable<T> which doesn’t use Expression Trees internally. For instance if you look at the below IEnumerable<T> interface definition,it doesn’t have an Expression defined in it.
2,332 total views, 1 views today