better handling of null and simple expression null checking.
This commit is contained in:
		
							parent
							
								
									904d3c9945
								
							
						
					
					
						commit
						62fa1a4d21
					
				| @ -15,7 +15,7 @@ namespace PoweredSoft.DynamicLinq.ConsoleApp | ||||
|         static void Main(string[] args) | ||||
|         { | ||||
|             var selectTests = new SelectTests(); | ||||
|             selectTests.SelectNullChecking(); | ||||
|             selectTests.SelectNullChecking2(); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
|  | ||||
| @ -82,6 +82,7 @@ namespace PoweredSoft.DynamicLinq.Test | ||||
|         { | ||||
|             var query = TestData.Authors.AsQueryable(); | ||||
| 
 | ||||
|              | ||||
|             var qs = query.Select(t => new | ||||
|             { | ||||
|                 CommentLikes = t.Posts == null ?  | ||||
| @ -128,7 +129,8 @@ namespace PoweredSoft.DynamicLinq.Test | ||||
|             { | ||||
|                 t.NullChecking(true); | ||||
|                 // this needs to be fixed. | ||||
|                 t.PathToList("Comment.Post.Comments.CommentText", selectCollectionHandling: SelectCollectionHandling.Flatten); | ||||
|                 t.Path("Comment.CommentText", "CommentText2"); | ||||
|                 //t.PathToList("Comment.Post.Comments.CommentText", selectCollectionHandling: SelectCollectionHandling.Flatten); | ||||
|             }); | ||||
| 
 | ||||
|             var b = querySelect.ToDynamicClassList(); | ||||
|  | ||||
| @ -208,7 +208,11 @@ namespace PoweredSoft.DynamicLinq.Helpers | ||||
|         { | ||||
|             if (selectType == SelectTypes.Path) | ||||
|             { | ||||
|                 return ResolvePathForExpression(parameter, path); | ||||
|                 var parser = new ExpressionParser(parameter, path); | ||||
|                 var resolver = new PathExpressionResolver(parser); | ||||
|                 resolver.NullChecking = nullChecking; | ||||
|                 resolver.Resolve(); | ||||
|                 return resolver.GetResultBodyExpression(); | ||||
|             } | ||||
|             else if (selectType == SelectTypes.PathToList) | ||||
|             { | ||||
|  | ||||
| @ -15,7 +15,6 @@ namespace PoweredSoft.DynamicLinq.Resolver | ||||
|         public ExpressionParser Parser { get; protected set; } | ||||
| 
 | ||||
|         public Expression Result { get; protected set; } | ||||
|         public Type NullType { get; set; } | ||||
| 
 | ||||
|         public PathExpressionResolver(ExpressionParser parser) | ||||
|         { | ||||
| @ -55,7 +54,11 @@ namespace PoweredSoft.DynamicLinq.Resolver | ||||
| 
 | ||||
|                     if (group.Parent == null) | ||||
|                     { | ||||
|                         currentExpression = groupExpressionLambda; | ||||
|                         currentExpression = groupExpression; | ||||
|                         if (NullChecking != false) | ||||
|                             currentExpression = CheckNullOnFirstGroup(group, currentExpression); | ||||
| 
 | ||||
|                         currentExpression = Expression.Lambda(currentExpression, group.Parameter); | ||||
|                         continue; | ||||
|                     } | ||||
| 
 | ||||
| @ -128,10 +131,14 @@ namespace PoweredSoft.DynamicLinq.Resolver | ||||
|         { | ||||
|             var path = string.Join(".", group.Pieces.Select(t => t.Name)); | ||||
|             var whereExpression = QueryableHelpers.CreateConditionExpression(group.Parameter.Type, path, | ||||
|                     ConditionOperators.Equal, null, QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, | ||||
|                     ConditionOperators.NotEqual, null, QueryConvertStrategy.ConvertConstantToComparedPropertyOrField, | ||||
|                     parameter: group.Parameter, nullChecking: true); | ||||
| 
 | ||||
|             var whereBodyExpression = (whereExpression as LambdaExpression).Body; | ||||
|             whereBodyExpression =Expression.Not(whereBodyExpression); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|             var nullType = currentExpression.Type; | ||||
|             Expression ifTrueExpression = null; | ||||
| @ -143,7 +150,7 @@ namespace PoweredSoft.DynamicLinq.Resolver | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 ifTrueExpression = Expression.Default(NullType); | ||||
|                 ifTrueExpression = Expression.Default(nullType); | ||||
|             } | ||||
| 
 | ||||
|             return Expression.Condition(whereBodyExpression, ifTrueExpression, currentExpression, currentExpression.Type); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user