@@ -119,10 +119,10 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
119119
120120 try
121121 {
122- if ( filterQuery . FilterOperation == FilterOperations . @in )
122+ if ( filterQuery . FilterOperation == FilterOperations . @in || filterQuery . FilterOperation == FilterOperations . nin )
123123 {
124124 string [ ] propertyValues = filterQuery . PropertyValue . Split ( ',' ) ;
125- var lambdaIn = ArrayContainsPredicate < TSource > ( propertyValues , property . Name ) ;
125+ var lambdaIn = ArrayContainsPredicate < TSource > ( propertyValues , property . Name , filterQuery . FilterOperation ) ;
126126
127127 return source . Where ( lambdaIn ) ;
128128 }
@@ -167,10 +167,10 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
167167
168168 try
169169 {
170- if ( filterQuery . FilterOperation == FilterOperations . @in )
170+ if ( filterQuery . FilterOperation == FilterOperations . @in || filterQuery . FilterOperation == FilterOperations . nin )
171171 {
172172 string [ ] propertyValues = filterQuery . PropertyValue . Split ( ',' ) ;
173- var lambdaIn = ArrayContainsPredicate < TSource > ( propertyValues , relatedAttr . Name , relation . Name ) ;
173+ var lambdaIn = ArrayContainsPredicate < TSource > ( propertyValues , relatedAttr . Name , filterQuery . FilterOperation , relation . Name ) ;
174174
175175 return source . Where ( lambdaIn ) ;
176176 }
@@ -243,7 +243,7 @@ private static Expression GetFilterExpressionLambda(Expression left, Expression
243243 return body ;
244244 }
245245
246- private static Expression < Func < TSource , bool > > ArrayContainsPredicate < TSource > ( string [ ] propertyValues , string fieldname , string relationName = null )
246+ private static Expression < Func < TSource , bool > > ArrayContainsPredicate < TSource > ( string [ ] propertyValues , string fieldname , FilterOperations op , string relationName = null )
247247 {
248248 ParameterExpression entity = Expression . Parameter ( typeof ( TSource ) , "entity" ) ;
249249 MemberExpression member ;
@@ -258,8 +258,18 @@ private static Expression<Func<TSource, bool>> ArrayContainsPredicate<TSource>(s
258258 var method = ContainsMethod . MakeGenericMethod ( member . Type ) ;
259259 var obj = TypeHelper . ConvertListType ( propertyValues , member . Type ) ;
260260
261- var exprContains = Expression . Call ( method , new Expression [ ] { Expression . Constant ( obj ) , member } ) ;
262- return Expression . Lambda < Func < TSource , bool > > ( exprContains , entity ) ;
261+ if ( op == FilterOperations . @in )
262+ {
263+ // Where(i => arr.Contains(i.column))
264+ var contains = Expression . Call ( method , new Expression [ ] { Expression . Constant ( obj ) , member } ) ;
265+ return Expression . Lambda < Func < TSource , bool > > ( contains , entity ) ;
266+ }
267+ else
268+ {
269+ // Where(i => !arr.Contains(i.column))
270+ var notContains = Expression . Not ( Expression . Call ( method , new Expression [ ] { Expression . Constant ( obj ) , member } ) ) ;
271+ return Expression . Lambda < Func < TSource , bool > > ( notContains , entity ) ;
272+ }
263273 }
264274
265275 public static IQueryable < TSource > Select < TSource > ( this IQueryable < TSource > source , List < string > columns )
0 commit comments