select many support for flattening.

This commit is contained in:
David Lebee 2018-04-11 21:39:54 -05:00
parent 0e7aca052c
commit e961c38c99

View File

@ -66,12 +66,23 @@ namespace PoweredSoft.DynamicLinq.Resolver
parentExpression = CheckNullOnEnumerableParent(group, parent, parentExpression, isLastGroup);
// the select expression.
if (CollectionHandling == SelectCollectionHandling.Flatten && QueryableHelpers.IsGenericEnumerable(groupExpression))
{
var selectType = parent.GroupEnumerableType();
var selectExpression = Expression.Call(typeof(Enumerable), "SelectMany",
new Type[] { selectType, groupExpression.Type.GenericTypeArguments.First() },
parentExpression, groupExpressionLambda);
currentExpression = selectExpression;
}
else
{
var selectType = parent.GroupEnumerableType();
var selectExpression = Expression.Call(typeof(Enumerable), "Select",
new Type[] { selectType, groupExpression.Type },
parentExpression, groupExpressionLambda);
currentExpression = selectExpression;
}
}
else
{
if (group.Parent == null)
@ -91,12 +102,22 @@ namespace PoweredSoft.DynamicLinq.Resolver
if (NullChecking != false)
parentExpression = CheckNullOnEnumerableParent(group, parent, parentExpression, isLastGroup);
if (CollectionHandling == SelectCollectionHandling.Flatten && QueryableHelpers.IsGenericEnumerable(currentExpression))
{
var currentExpressionLambda = Expression.Lambda(currentExpression, group.Parameter);
currentExpression = Expression.Call(typeof(Enumerable), "SelectMany",
new Type[] { selectType, currentExpression.Type.GenericTypeArguments.First() },
parentExpression, currentExpressionLambda);
}
else
{
var currentExpressionLambda = Expression.Lambda(currentExpression, group.Parameter);
currentExpression = Expression.Call(typeof(Enumerable), "Select",
new Type[] { selectType, currentExpression.Type },
parentExpression, currentExpressionLambda);
}
}
}
Result = currentExpression;
}