flattening support on wrap select.

This commit is contained in:
David Lebee 2018-10-26 16:13:42 -05:00
parent aba20f04e2
commit a7937cd500
3 changed files with 11 additions and 16 deletions

View File

@ -9,6 +9,7 @@ using PoweredSoft.DynamicLinq.Dal;
using System.Diagnostics;
using PoweredSoft.DynamicLinq.Test.Helpers;
using System.Collections;
using PoweredSoft.DynamicLinq.Dal.Pocos;
namespace PoweredSoft.DynamicLinq.Test
{
@ -289,7 +290,7 @@ namespace PoweredSoft.DynamicLinq.Test
}
[TestMethod]
public void GroupByToListWithPathWithNullChecking()
public void GroupByToListWithPathWithNullCheckingWithFlattening()
{
var limitResult = TestData.Authors;
@ -300,7 +301,7 @@ namespace PoweredSoft.DynamicLinq.Test
.Select(t => new
{
Key = t.Key.AuthorFirstName,
Contents = t.SelectMany(t2 => t2.Posts.Select(t3 => t3.Content)).ToList()
Contents = t.SelectMany(t2 => t2.Posts == null ? new List<string>() : t2.Posts.Select(t3 => t3.Content)).ToList()
})
.ToList();

View File

@ -220,7 +220,13 @@ namespace PoweredSoft.DynamicLinq.Helpers
{
var selectType = parameter.Type.GenericTypeArguments.Skip(1).First();
var innerSelectType = ((LambdaExpression)innerLambdaExpression).ReturnType;
var selectExpression = Expression.Call(typeof(Enumerable), "Select", new Type[] { selectType, innerSelectType }, parameter, innerLambdaExpression);
Expression selectExpression;
if (QueryableHelpers.IsGenericEnumerable(innerSelectType) && selectCollectionHandling == SelectCollectionHandling.Flatten)
selectExpression = Expression.Call(typeof(Enumerable), "SelectMany", new Type[] { selectType, innerSelectType.GenericTypeArguments.First() }, parameter, innerLambdaExpression);
else
selectExpression = Expression.Call(typeof(Enumerable), "Select", new Type[] { selectType, innerSelectType }, parameter, innerLambdaExpression);
return selectExpression;
}

View File

@ -1,12 +0,0 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
namespace PoweredSoft.DynamicLinq.Helpers
{
public static class QueryablePathHelpers
{
}
}