@@ -171,14 +171,14 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
171171
172172 try
173173 {
174- if ( op == FilterOperationsEnum . @in || op == FilterOperationsEnum . nin )
174+ if ( op == FilterOperations . @in || op == FilterOperations . nin )
175175 {
176176 string [ ] propertyValues = filterQuery . PropertyValue . Split ( ',' ) ;
177177 var lambdaIn = ArrayContainsPredicate < TSource > ( propertyValues , property . Name , op ) ;
178178
179179 return source . Where ( lambdaIn ) ;
180180 }
181- else if ( op == FilterOperationsEnum . isnotnull || op == FilterOperationsEnum . isnull ) {
181+ else if ( op == FilterOperations . isnotnull || op == FilterOperations . isnull ) {
182182 // {model}
183183 var parameter = Expression . Parameter ( concreteType , "model" ) ;
184184 // {model.Id}
@@ -231,7 +231,7 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
231231
232232 try
233233 {
234- if ( filterQuery . FilterOperation == FilterOperationsEnum . @in || filterQuery . FilterOperation == FilterOperationsEnum . nin )
234+ if ( filterQuery . FilterOperation == FilterOperations . @in || filterQuery . FilterOperation == FilterOperations . nin )
235235 {
236236 string [ ] propertyValues = filterQuery . PropertyValue . Split ( ',' ) ;
237237 var lambdaIn = ArrayContainsPredicate < TSource > ( propertyValues , relatedAttr . Name , filterQuery . FilterOperation , relation . Name ) ;
@@ -271,43 +271,43 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
271271 private static bool IsNullable ( Type type ) => type . IsGenericType && type . GetGenericTypeDefinition ( ) == typeof ( Nullable < > ) ;
272272
273273
274- private static Expression GetFilterExpressionLambda ( Expression left , Expression right , FilterOperationsEnum operation )
274+ private static Expression GetFilterExpressionLambda ( Expression left , Expression right , FilterOperations operation )
275275 {
276276 Expression body ;
277277 switch ( operation )
278278 {
279- case FilterOperationsEnum . eq :
279+ case FilterOperations . eq :
280280 // {model.Id == 1}
281281 body = Expression . Equal ( left , right ) ;
282282 break ;
283- case FilterOperationsEnum . lt :
283+ case FilterOperations . lt :
284284 // {model.Id < 1}
285285 body = Expression . LessThan ( left , right ) ;
286286 break ;
287- case FilterOperationsEnum . gt :
287+ case FilterOperations . gt :
288288 // {model.Id > 1}
289289 body = Expression . GreaterThan ( left , right ) ;
290290 break ;
291- case FilterOperationsEnum . le :
291+ case FilterOperations . le :
292292 // {model.Id <= 1}
293293 body = Expression . LessThanOrEqual ( left , right ) ;
294294 break ;
295- case FilterOperationsEnum . ge :
295+ case FilterOperations . ge :
296296 // {model.Id >= 1}
297297 body = Expression . GreaterThanOrEqual ( left , right ) ;
298298 break ;
299- case FilterOperationsEnum . like :
299+ case FilterOperations . like :
300300 body = Expression . Call ( left , "Contains" , null , right ) ;
301301 break ;
302302 // {model.Id != 1}
303- case FilterOperationsEnum . ne :
303+ case FilterOperations . ne :
304304 body = Expression . NotEqual ( left , right ) ;
305305 break ;
306- case FilterOperationsEnum . isnotnull :
306+ case FilterOperations . isnotnull :
307307 // {model.Id != null}
308308 body = Expression . NotEqual ( left , right ) ;
309309 break ;
310- case FilterOperationsEnum . isnull :
310+ case FilterOperations . isnull :
311311 // {model.Id == null}
312312 body = Expression . Equal ( left , right ) ;
313313 break ;
@@ -318,7 +318,7 @@ private static Expression GetFilterExpressionLambda(Expression left, Expression
318318 return body ;
319319 }
320320
321- private static Expression < Func < TSource , bool > > ArrayContainsPredicate < TSource > ( string [ ] propertyValues , string fieldname , FilterOperationsEnum op , string relationName = null )
321+ private static Expression < Func < TSource , bool > > ArrayContainsPredicate < TSource > ( string [ ] propertyValues , string fieldname , FilterOperations op , string relationName = null )
322322 {
323323 ParameterExpression entity = Expression . Parameter ( typeof ( TSource ) , "entity" ) ;
324324 MemberExpression member ;
@@ -333,7 +333,7 @@ private static Expression<Func<TSource, bool>> ArrayContainsPredicate<TSource>(s
333333 var method = ContainsMethod . MakeGenericMethod ( member . Type ) ;
334334 var obj = TypeHelper . ConvertListType ( propertyValues , member . Type ) ;
335335
336- if ( op == FilterOperationsEnum . @in )
336+ if ( op == FilterOperations . @in )
337337 {
338338 // Where(i => arr.Contains(i.column))
339339 var contains = Expression . Call ( method , new Expression [ ] { Expression . Constant ( obj ) , member } ) ;
@@ -347,44 +347,20 @@ private static Expression<Func<TSource, bool>> ArrayContainsPredicate<TSource>(s
347347 }
348348 }
349349
350- public static IQueryable < TSource > Select < TSource > ( this IQueryable < TSource > source , List < QueryAttribute > columns )
350+ public static IQueryable < TSource > Select < TSource > ( this IQueryable < TSource > source , List < string > columns )
351351 {
352352 if ( columns == null || columns . Count == 0 )
353353 return source ;
354354
355355 var sourceType = source . ElementType ;
356+
356357 var resultType = typeof ( TSource ) ;
357358
358359 // {model}
359360 var parameter = Expression . Parameter ( sourceType , "model" ) ;
360- var attrs = new List < string > ( ) ;
361- // Key = Relationship, Value = Attribute
362- var relationAttrs = new Dictionary < string , string > ( ) ;
363- foreach ( var item in columns )
364- {
365- if ( item . IsAttributeOfRelationship )
366- relationAttrs . Add ( item . RelationshipAttribute , item . Attribute ) ;
367- else
368- attrs . Add ( item . Attribute ) ;
369- }
370-
371- var bindings = new List < MemberAssignment > ( ) ;
372- bindings . AddRange ( attrs . Select ( column => Expression . Bind ( resultType . GetProperty ( column ) , Expression . PropertyOrField ( parameter , column ) ) ) ) ;
373-
374-
375- //foreach (var relationAttr in relationAttrs)
376- //{
377- // var relation = Expression.PropertyOrField(parameter, relationAttr.Key);
378- // var member = Expression.Property(relation, relationAttr.Value);
379- // var relationType = member.Type;
380-
381- // var relationshipBindings = new List<MemberAssignment>();
382- // relationshipBindings.AddRange(attrs.Select(column => Expression.Bind(resultType.GetProperty(column), Expression.PropertyOrField(parameter, column))));
383361
384- // var body = Expression.MemberInit(Expression.New(relation.Type), bindings);
385- // var ah = Expression.Bind(relation.Member, member.Expression);
386- // bindings.Add(ah);
387- //}
362+ var bindings = columns . Select ( column => Expression . Bind (
363+ resultType . GetProperty ( column ) , Expression . PropertyOrField ( parameter , column ) ) ) ;
388364
389365 // { new Model () { Property = model.Property } }
390366 var body = Expression . MemberInit ( Expression . New ( resultType ) , bindings ) ;
0 commit comments