What is Expression Trees and how they used in LINQ?

Technology CommunityCategory: LINQWhat is Expression Trees and how they used in LINQ?
VietMX Staff asked 3 years ago

An Expression Tree is a data structure that contains Expressions, which is basically code. So it is a tree structure that represents a calculation you may make in code. These pieces of code can then be executed by “running” the expression tree over a set of data.

In LINQ, expression trees are used to represent structured queries that target sources of data that implement IQueryable<T>. For example, the LINQ provider implements the IQueryable<T> interface for querying relational data stores. The C# compiler compiles queries that target such data sources into code that builds an expression tree at runtime. The query provider can then traverse the expression tree data structure and translate it into a query language appropriate for the data source.