.net-Linq the use of Expression<T>
Can you开发者_开发问答 Explain the terms Expression Tree... Expression in Linq ?
I'd recommend reading up on Expression Trees on MSDN.
They're most commonly used with LINQ when using IQueryable<T>
, ie: LINQ to Sql or Entity Framework and similar. The lambda expression you pass to a LINQ query gets turned into an expression tree, which is a way to "represent code in a tree-like data structure".
This allows the provider in question to turn this into an actual SQL database call, since it can parse the expression tree and translate it into something the database understands natively.
That being said, this can be used in other places, as well. Any time you need to represent "code" and build it up, you can use expression trees. For example, this is often used to implement INotifyPropertyChanged without requiring strings to be passed.
精彩评论