I have a list and a query simply defined as this:
var list = new List<int>();
for (var i = 0; i < 4; i++)
{
list.Add(i);
}
var query = list.AsQueryable();
Now I have an Expression
which returns the square of the number:
private static Expression<Func<int, int>> Square()
{
return i => i * i;
}
and the third power like this:
private static Expression<Func<int, int>> Third()
{
return i => i * i * i;
}
What I want is to be able to select the sum of these in the Select
expression with a code similar to this pseudocode:
var result = query.Select(Square() + Third()).ToList();
I expect the result to be
0
2
12
36
Is there a way to easily achieve that or I should do it some other way?
P.S. keep in mind, the methods are simplified to stress for ease of defining the issue.
P.S. I am using expressions because this is oversimplified example of the Linq-to-entities issue and I understood that I can only use IQueryable
as of this topic.