If I have a collection of Expression<Func<TSource, object>>
Select expressions
like e => e.Id
and e => e.Name
How can I combine them to create one expresion like:
Select{ e => new {e => e.Id, e => e.Name}}
Edited
I have method helper to get lambda select expression from list of field or properties
public static ICollection<Expression<Func<IQueryable<TSource>, object>>> BuildSelectExpressionCollection<TSource>(this IEnumerable<string> selects)
It simply use property like "Id" and convert to some lambda expression
But I want to cope with this collection of expressions
To execute Select with linq query
But if I use it in cycle
It can build many Select expression like:
someQueryableCollection.Select(e=>e.Id).Selct(e=>e.Name) and so on
If it possible to combine then in one Select query?
Edited 2
1.I accept some select query from url ($select=Name,Id)
2.Then I have method to get all properties from select query to list (List list = this fiels that I get (Name, Id))
3.The problem is that I have url query to DTO model but I want to convert it to entity Model filds and than execute query to return only Name and Id
What I have done so far:
- get list of lambda expression to property fields like e=>e.Id and so on
- than I use expression visitor to convert lambda expressions acording to fields of entity model
- but this is a problem that compiler can resolve type of lambda expression at runtime and how to combine lambdas in one select query?