Related To :
Create a Lambda Expression With 3 conditions
Convert Contains To Expression Tree
Convert List.Contains to Expression Tree
Please consider above questions.
I want to write a query for this:
using (MyEntities context = new MyEntities())
{
var DbSet = context.CreateObjectSet<T>();
var Max = DbSet.Where(exp).Select(selector).Max();
}
I don't know how to write a code for selector
. What Select
overload I should use? and How I can write that using Expression Tree?
Thanks
The one with a single parameter in addition to the source:
Selector needs to take a
TSource
parameter, and produce the field of which you want to retrieve theMax
. For example, let's sayTSource
is of typeEmployee
, and you want to find theMax
of itsSalary
property of typedecimal
. Then you would create an expression tree like this: