If I work with LINQ to Objects, I can use Func<TIn, TOut>in Select, for example:
Enumerable.Range(1, 10).Select(x => new { A = x, B = SomeFunc });
where SomeFuncit looks something like this:
Func<int, long> SomeFunc = x => x * x;
But working with LINQ to Entities, Func does not work, I have to use Expression. And this code does not work:
var query = Enumerable.Range(1, 10)
.AsQueryable()
.Select(x => new { A = x, B = SomeExpr });
where SomeExprit looks something like this:
Expression<Func<int, long>> SomeExpr = x => x * x;
How to use expressions in Select in a query?
source
share