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); parentExpression = CheckNullOnEnumerableParent(group, parent, parentExpression, isLastGroup);
// the select expression. // 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 selectType = parent.GroupEnumerableType();
var selectExpression = Expression.Call(typeof(Enumerable), "Select", var selectExpression = Expression.Call(typeof(Enumerable), "Select",
new Type[] { selectType, groupExpression.Type }, new Type[] { selectType, groupExpression.Type },
parentExpression, groupExpressionLambda); parentExpression, groupExpressionLambda);
currentExpression = selectExpression; currentExpression = selectExpression;
} }
}
else else
{ {
if (group.Parent == null) if (group.Parent == null)
@ -91,12 +102,22 @@ namespace PoweredSoft.DynamicLinq.Resolver
if (NullChecking != false) if (NullChecking != false)
parentExpression = CheckNullOnEnumerableParent(group, parent, parentExpression, isLastGroup); 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); var currentExpressionLambda = Expression.Lambda(currentExpression, group.Parameter);
currentExpression = Expression.Call(typeof(Enumerable), "Select", currentExpression = Expression.Call(typeof(Enumerable), "Select",
new Type[] { selectType, currentExpression.Type }, new Type[] { selectType, currentExpression.Type },
parentExpression, currentExpressionLambda); parentExpression, currentExpressionLambda);
} }
} }
}
Result = currentExpression; Result = currentExpression;
} }