@@ -88,15 +88,27 @@ Expression CompileBinary(ParameterExpression dataItemExpr, IList criteriaJson) {
8888 if ( _stringToLower && clientValue is String )
8989 clientValue = ( ( string ) clientValue ) . ToLower ( ) ;
9090
91+ if ( ( accessorExpr . Type == typeof ( Guid ) || accessorExpr . Type == typeof ( Guid ? ) ) && IsInequality ( expressionType ) )
92+ return CompileGuidComparison ( accessorExpr , expressionType , clientValue ) ;
93+
9194 Expression valueExpr = Expression . Constant ( clientValue , accessorExpr . Type ) ;
9295
9396 if ( accessorExpr . Type == typeof ( String ) && IsInequality ( expressionType ) ) {
9497 var compareMethod = typeof ( String ) . GetMethod ( nameof ( String . Compare ) , new [ ] { typeof ( String ) , typeof ( String ) } ) ;
95- accessorExpr = Expression . Call ( null , compareMethod , accessorExpr , valueExpr ) ;
96- valueExpr = Expression . Constant ( 0 ) ;
97- } else if ( useDynamicBinding ) {
98- accessorExpr = Expression . Call ( typeof ( Utils ) . GetMethod ( nameof ( Utils . DynamicCompare ) ) , accessorExpr , valueExpr ) ;
99- valueExpr = Expression . Constant ( 0 ) ;
98+ return Expression . MakeBinary (
99+ expressionType ,
100+ Expression . Call ( compareMethod , accessorExpr , valueExpr ) ,
101+ Expression . Constant ( 0 )
102+ ) ;
103+ }
104+
105+ if ( useDynamicBinding ) {
106+ var compareMethod = typeof ( Utils ) . GetMethod ( nameof ( Utils . DynamicCompare ) ) ;
107+ return Expression . MakeBinary (
108+ expressionType ,
109+ Expression . Call ( compareMethod , accessorExpr , valueExpr ) ,
110+ Expression . Constant ( 0 )
111+ ) ;
100112 }
101113
102114 return Expression . MakeBinary ( expressionType , accessorExpr , valueExpr ) ;
@@ -108,6 +120,31 @@ bool IsInequality(ExpressionType type) {
108120 return type == ExpressionType . LessThan || type == ExpressionType . LessThanOrEqual || type == ExpressionType . GreaterThanOrEqual || type == ExpressionType . GreaterThan ;
109121 }
110122
123+ Expression CompileGuidComparison ( Expression accessorExpr , ExpressionType expressionType , object clientValue ) {
124+ if ( clientValue == null )
125+ return Expression . Constant ( false ) ;
126+
127+ var result = Expression . MakeBinary (
128+ expressionType ,
129+ Expression . Call (
130+ Utils . IsNullable ( accessorExpr . Type ) ? Expression . Property ( accessorExpr , "Value" ) : accessorExpr ,
131+ typeof ( Guid ) . GetMethod ( nameof ( Guid . CompareTo ) , new [ ] { typeof ( Guid ) } ) ,
132+ Expression . Constant ( clientValue , typeof ( Guid ) )
133+ ) ,
134+ Expression . Constant ( 0 )
135+ ) ;
136+
137+ if ( GuardNulls ) {
138+ return Expression . Condition (
139+ Expression . MakeBinary ( ExpressionType . Equal , accessorExpr , Expression . Constant ( null ) ) ,
140+ Expression . Constant ( false ) ,
141+ result
142+ ) ;
143+ }
144+
145+ return result ;
146+ }
147+
111148 Expression CompileStringFunction ( Expression accessorExpr , string clientOperation , string value ) {
112149 if ( _stringToLower && value != null )
113150 value = value . ToLower ( ) ;
0 commit comments