@@ -119,10 +119,10 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
119
119
120
120
try
121
121
{
122
- if ( filterQuery . FilterOperation == FilterOperations . @in )
122
+ if ( filterQuery . FilterOperation == FilterOperations . @in || filterQuery . FilterOperation == FilterOperations . nin )
123
123
{
124
124
string [ ] propertyValues = filterQuery . PropertyValue . Split ( ',' ) ;
125
- var lambdaIn = ArrayContainsPredicate < TSource > ( propertyValues , property . Name ) ;
125
+ var lambdaIn = ArrayContainsPredicate < TSource > ( propertyValues , property . Name , filterQuery . FilterOperation ) ;
126
126
127
127
return source . Where ( lambdaIn ) ;
128
128
}
@@ -167,10 +167,10 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
167
167
168
168
try
169
169
{
170
- if ( filterQuery . FilterOperation == FilterOperations . @in )
170
+ if ( filterQuery . FilterOperation == FilterOperations . @in || filterQuery . FilterOperation == FilterOperations . nin )
171
171
{
172
172
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 ) ;
174
174
175
175
return source . Where ( lambdaIn ) ;
176
176
}
@@ -243,7 +243,7 @@ private static Expression GetFilterExpressionLambda(Expression left, Expression
243
243
return body ;
244
244
}
245
245
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 )
247
247
{
248
248
ParameterExpression entity = Expression . Parameter ( typeof ( TSource ) , "entity" ) ;
249
249
MemberExpression member ;
@@ -258,8 +258,18 @@ private static Expression<Func<TSource, bool>> ArrayContainsPredicate<TSource>(s
258
258
var method = ContainsMethod . MakeGenericMethod ( member . Type ) ;
259
259
var obj = TypeHelper . ConvertListType ( propertyValues , member . Type ) ;
260
260
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
+ }
263
273
}
264
274
265
275
public static IQueryable < TSource > Select < TSource > ( this IQueryable < TSource > source , List < string > columns )
0 commit comments