From 8ae2b2313bb01283af50ed5a7bd7c8029eb479ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Leb=C3=A9e?= Date: Tue, 10 Apr 2018 19:08:31 -0500 Subject: [PATCH] One Step closer to get the null checking :D --- .../BetterProto2.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/PoweredSoft.DynamicLinq.ConsoleApp/BetterProto2.cs b/PoweredSoft.DynamicLinq.ConsoleApp/BetterProto2.cs index 7635a0a..f0b095d 100644 --- a/PoweredSoft.DynamicLinq.ConsoleApp/BetterProto2.cs +++ b/PoweredSoft.DynamicLinq.ConsoleApp/BetterProto2.cs @@ -49,7 +49,8 @@ namespace PoweredSoft.DynamicLinq.ConsoleApp new List().AsQueryable().Select(t => new { - A = t.Posts.Select(t2 => t2.Author.Posts.Select(t3 => t3.Author.Website.Url)) + A = t.Posts.Select(t2 => t2.Author.Posts.Select(t3 => t3.Author.Website.Url)) , + B = t.Posts.Where(t2 => t2.Author != null).Select(t2 => t2.Author.Posts.Where(t3 => t3.Author != null && t3.Author.Website != null).Select(t3 => t3.Author.Website.Url)) }); new List().AsQueryable().Select(t => new @@ -141,7 +142,6 @@ namespace PoweredSoft.DynamicLinq.ConsoleApp parentExpression = Expression.Call(typeof(Enumerable), "Where", new Type[] { parent.GroupEnumerableType() }, parentExpression, whereExpression); - } } @@ -163,6 +163,24 @@ namespace PoweredSoft.DynamicLinq.ConsoleApp var parent = group.Parent; var parentExpression = CompileGroup(parent, NullHandling); var selectType = parent.GroupEnumerableType(); + + + if (NullHandling != SelectNullHandling.LeaveAsIs) + { + if (group.Pieces.Count > 1) + { + var path = string.Join(".", group.Pieces.Take(group.Pieces.Count - 1).Select(T => T.Name)); + var whereExpression = QueryableHelpers.CreateConditionExpression(group.Parameter.Type, path, + ConditionOperators.NotEqual, null, QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, + parameter: group.Parameter, nullChecking: true); + + //public static IEnumerable Where(this IEnumerable source, Func predicate); + parentExpression = Expression.Call(typeof(Enumerable), "Where", + new Type[] { parent.GroupEnumerableType() }, + parentExpression, whereExpression); + } + } + var currentExpressionLambda = Expression.Lambda(currentExpression, group.Parameter); currentExpression = Expression.Call(typeof(Enumerable), "Select", new Type[] { selectType, currentExpression.Type },