Lambdas can be emitted both as Func and Expression
suggest changeAssuming the following Person class:
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
The following lambda:
p => p.Age > 18
can be passed as an argument to both methods:
public void AsFunc(Func<Person, bool> func)
public void AsExpression(Expression<Func<Person, bool>> expr)
The compiler can turn an expression-bodied lambda into either a delegate or an expression tree. A statement-bodied lambda can become a delegate, but not an expression tree.
LINQ providers rely on expression trees, mainly through IQueryable<T>, to parse a query and translate it into a store query.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents