In System.Linq.Dynamic, there are a few methods to form Select, Where and other Linq statements dynamically. But there is no for SelectMany.
The method for Select is as the following:
public static IQueryable Select(this IQueryable source, string selector, params object[] values)
{
if (source == null) throw new ArgumentNullException("source");
if (selector == null) throw new ArgumentNullException("selector");
LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, null, selector, values);
IQueryable result = source.Provider.CreateQuery(
Expression.Call(
typeof(Queryable), "Select",
new Type[] { source.ElementType, lambda.Body.Type },
source.Expression, Expression.Quote(lambda)));
return result;
}
I tried to modify the above code, after hours working, I couldn't find a way out.
Any suggestions are welcome.
Ying
I have added another SelectMany that retuns an AnonymousType.
I still need to figure out how to do the following using Dynamic, the goal is to return a new result object.
I am using the NWDB when I try:
I get an error because
CompanyName
is inCustomers
notOrders
. So it is not seeing the combination of the two objects. When I do:It returns the desired result.
Already implemented this one for our project, let me know if it works for you!