@@ -73,9 +73,7 @@ private static Result<Expression> EvaluatePropertyPathExpression(
7373 FilterEvaluationContext context
7474 )
7575 {
76- var baseExpression = context . IsInLambdaScope
77- ? ( Expression ) context . CurrentLambda . Parameter
78- : context . RootParameter ;
76+ var baseExpression = context . GetBaseExpression ( ) ;
7977
8078 var propertyPathResult = BuildPropertyPath (
8179 propertyPath ,
@@ -89,15 +87,10 @@ FilterEvaluationContext context
8987
9088 if ( exp . Right is NullLiteral )
9189 {
92- var nullComparison = CreateNullComparison ( exp , finalProperty ) ;
93- return nullComparison ;
90+ return CreateNullComparison ( exp , finalProperty ) ;
9491 }
9592
96- var comparisonResult = EvaluateValueComparison ( exp , finalProperty ) ;
97- if ( comparisonResult . IsFailed )
98- return comparisonResult ;
99-
100- return comparisonResult . Value ;
93+ return EvaluateValueComparison ( exp , finalProperty ) ;
10194 }
10295
10396 private static Result < MemberExpression > BuildPropertyPath (
@@ -132,16 +125,6 @@ PropertyMappingTree propertyMappingTree
132125 return Result . Ok ( ( MemberExpression ) result . Value ) ;
133126 }
134127
135- private static bool IsPrimitiveType ( Type type )
136- {
137- return type . IsPrimitive
138- || type == typeof ( string )
139- || type == typeof ( decimal )
140- || type == typeof ( DateTime )
141- || type == typeof ( Guid )
142- || Nullable . GetUnderlyingType ( type ) != null ;
143- }
144-
145128 private static Expression CreateNullComparison ( InfixExpression exp , MemberExpression property )
146129 {
147130 return exp . Operator == Keywords . Eq
@@ -261,6 +244,7 @@ Expression expression
261244 return literal switch
262245 {
263246 IntegerLiteral intLit => CreateIntegerOrEnumConstant ( intLit . Value , expression . Type ) ,
247+ LongLiteral longLit => CreateLongConstant ( longLit . Value , expression . Type ) ,
264248 DateLiteral dateLit => Result . Ok ( CreateDateConstant ( dateLit , expression . Type ) ) ,
265249 GuidLiteral guidLit => Result . Ok ( Expression . Constant ( guidLit . Value , expression . Type ) ) ,
266250 DecimalLiteral decLit => Result . Ok ( Expression . Constant ( decLit . Value , expression . Type ) ) ,
@@ -416,9 +400,7 @@ FilterEvaluationContext context
416400 return Result . Fail ( $ "Invalid property '{ identifier } ' within filter") ;
417401 }
418402
419- var baseExpression = context . IsInLambdaScope
420- ? ( Expression ) context . CurrentLambda . Parameter
421- : context . RootParameter ;
403+ var baseExpression = context . GetBaseExpression ( ) ;
422404
423405 var identifierProperty = Expression . Property (
424406 baseExpression ,
@@ -488,9 +470,7 @@ FilterEvaluationContext context
488470 ParameterExpression Parameter
489471 ) > SetupLambdaEvaluation ( QueryLambdaExpression lambdaExp , FilterEvaluationContext context )
490472 {
491- var baseExpression = context . IsInLambdaScope
492- ? ( Expression ) context . CurrentLambda . Parameter
493- : context . RootParameter ;
473+ var baseExpression = context . GetBaseExpression ( ) ;
494474
495475 var collectionResult = ResolveCollectionProperty (
496476 lambdaExp . Property ,
@@ -629,7 +609,7 @@ FilterEvaluationContext context
629609 )
630610 {
631611 // For primitive types (string, int, etc.), allow direct comparisons with the lambda parameter
632- if ( IsPrimitiveType ( context . CurrentLambda . ElementType ) )
612+ if ( PropertyMappingTreeBuilder . IsPrimitiveType ( context . CurrentLambda . ElementType ) )
633613 {
634614 return EvaluateValueComparison ( exp , context . CurrentLambda . Parameter ) ;
635615 }
@@ -811,6 +791,39 @@ Type targetType
811791 }
812792 }
813793
794+ private static Result < ConstantExpression > CreateLongConstant ( long value , Type targetType )
795+ {
796+ try
797+ {
798+ var type = GetNonNullableType ( targetType ) ;
799+
800+ object convertedValue = type switch
801+ {
802+ Type t when t == typeof ( long ) => value ,
803+ Type t when t == typeof ( int ) => Convert . ToInt32 ( value ) ,
804+ Type t when t == typeof ( short ) => Convert . ToInt16 ( value ) ,
805+ Type t when t == typeof ( byte ) => Convert . ToByte ( value ) ,
806+ Type t when t == typeof ( uint ) => Convert . ToUInt32 ( value ) ,
807+ Type t when t == typeof ( ulong ) => Convert . ToUInt64 ( value ) ,
808+ Type t when t == typeof ( ushort ) => Convert . ToUInt16 ( value ) ,
809+ Type t when t == typeof ( sbyte ) => Convert . ToSByte ( value ) ,
810+ _ => throw new NotSupportedException (
811+ $ "Unsupported numeric type: { targetType . Name } "
812+ ) ,
813+ } ;
814+
815+ return Expression . Constant ( convertedValue , targetType ) ;
816+ }
817+ catch ( OverflowException )
818+ {
819+ return Result . Fail ( $ "Value { value } is too large for type { targetType . Name } ") ;
820+ }
821+ catch ( Exception )
822+ {
823+ return Result . Fail ( $ "Error converting { value } to { targetType . Name } ") ;
824+ }
825+ }
826+
814827 private static Result < ConstantExpression > CreateIntegerOrEnumConstant (
815828 int value ,
816829 Type targetType
0 commit comments