@@ -29,60 +29,37 @@ private static MethodInfo ContainsMethod
29
29
}
30
30
}
31
31
32
- public static IQueryable < TSource > Sort < TSource > ( this IQueryable < TSource > source , IJsonApiContext jsonApiContext , List < SortQuery > sortQueries )
32
+ public static IQueryable < TSource > Sort < TSource > ( this IQueryable < TSource > source , List < SortQuery > sortQueries )
33
33
{
34
34
if ( sortQueries == null || sortQueries . Count == 0 )
35
35
return source ;
36
36
37
- var orderedEntities = source . Sort ( jsonApiContext , sortQueries [ 0 ] ) ;
37
+ var orderedEntities = source . Sort ( sortQueries [ 0 ] ) ;
38
38
39
39
if ( sortQueries . Count <= 1 )
40
40
return orderedEntities ;
41
41
42
42
for ( var i = 1 ; i < sortQueries . Count ; i ++ )
43
- orderedEntities = orderedEntities . Sort ( jsonApiContext , sortQueries [ i ] ) ;
43
+ orderedEntities = orderedEntities . Sort ( sortQueries [ i ] ) ;
44
44
45
45
return orderedEntities ;
46
46
}
47
47
48
- public static IOrderedQueryable < TSource > Sort < TSource > ( this IQueryable < TSource > source , IJsonApiContext jsonApiContext , SortQuery sortQuery )
48
+ public static IOrderedQueryable < TSource > Sort < TSource > ( this IQueryable < TSource > source , SortQuery sortQuery )
49
49
{
50
- if ( sortQuery . IsAttributeOfRelationship )
51
- {
52
- // For now is created new instance, later resolve from cache
53
- var relatedAttrQuery = new RelatedAttrQuery ( jsonApiContext , sortQuery ) ;
54
- var path = relatedAttrQuery . GetRelatedPropertyPath ( ) ;
55
- return sortQuery . Direction == SortDirection . Descending
56
- ? source . OrderByDescending ( path )
57
- : source . OrderBy ( path ) ;
58
- }
59
- else
60
- {
61
- var attrQuery = new AttrQuery ( jsonApiContext , sortQuery ) ;
62
- return sortQuery . Direction == SortDirection . Descending
63
- ? source . OrderByDescending ( attrQuery . Attribute . InternalAttributeName )
64
- : source . OrderBy ( attrQuery . Attribute . InternalAttributeName ) ;
65
- }
50
+ var path = sortQuery . GetPropertyPath ( ) ;
51
+ return sortQuery . Direction == SortDirection . Descending
52
+ ? source . OrderByDescending ( path )
53
+ : source . OrderBy ( path ) ;
66
54
}
67
55
68
- public static IOrderedQueryable < TSource > Sort < TSource > ( this IOrderedQueryable < TSource > source , IJsonApiContext jsonApiContext , SortQuery sortQuery )
56
+ public static IOrderedQueryable < TSource > Sort < TSource > ( this IOrderedQueryable < TSource > source , SortQuery sortQuery )
69
57
{
70
- if ( sortQuery . IsAttributeOfRelationship )
71
- {
72
- var relatedAttrQuery = new RelatedAttrQuery ( jsonApiContext , sortQuery ) ;
73
- var path = relatedAttrQuery . GetRelatedPropertyPath ( ) ;
74
- return sortQuery . Direction == SortDirection . Descending
75
- ? source . OrderByDescending ( path )
76
- : source . OrderBy ( path ) ;
77
- }
78
- else
79
- {
80
- var attrQuery = new AttrQuery ( jsonApiContext , sortQuery ) ;
81
- return sortQuery . Direction == SortDirection . Descending
82
- ? source . OrderByDescending ( attrQuery . Attribute . InternalAttributeName )
83
- : source . OrderBy ( attrQuery . Attribute . InternalAttributeName ) ;
84
- }
85
- }
58
+ var path = sortQuery . GetPropertyPath ( ) ;
59
+ return sortQuery . Direction == SortDirection . Descending
60
+ ? source . OrderByDescending ( path )
61
+ : source . OrderBy ( path ) ;
62
+ }
86
63
87
64
public static IOrderedQueryable < TSource > OrderBy < TSource > ( this IQueryable < TSource > source , string propertyName )
88
65
=> CallGenericOrderMethod ( source , propertyName , "OrderBy" ) ;
@@ -101,13 +78,15 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
101
78
if ( filterQuery == null )
102
79
return source ;
103
80
104
- if ( filterQuery . IsAttributeOfRelationship )
105
- return source . Filter ( new RelatedAttrQuery ( jsonApiContext , filterQuery ) ) ;
81
+ // Relationship.Attribute
82
+ if ( ( filterQuery . IsStringBasedInit && filterQuery . Attribute . Contains ( QueryConstants . DOT ) )
83
+ || filterQuery . IsAttributeOfRelationship )
84
+ return source . Filter ( new RelatedAttrFilterQuery ( jsonApiContext , filterQuery ) ) ;
106
85
107
- return source . Filter ( new AttrQuery ( jsonApiContext , filterQuery ) ) ;
86
+ return source . Filter ( new AttrFilterQuery ( jsonApiContext , filterQuery ) ) ;
108
87
}
109
88
110
- public static IQueryable < TSource > Filter < TSource > ( this IQueryable < TSource > source , BaseAttrQuery filterQuery )
89
+ public static IQueryable < TSource > Filter < TSource > ( this IQueryable < TSource > source , BaseFilterQuery filterQuery )
111
90
{
112
91
if ( filterQuery == null )
113
92
return source ;
@@ -238,7 +217,7 @@ private static IOrderedQueryable<TSource> CallGenericOrderMethod<TSource>(IQuery
238
217
return ( IOrderedQueryable < TSource > ) result ;
239
218
}
240
219
241
- private static IQueryable < TSource > CallGenericWhereMethod < TSource > ( IQueryable < TSource > source , BaseAttrQuery filter )
220
+ private static IQueryable < TSource > CallGenericWhereMethod < TSource > ( IQueryable < TSource > source , BaseFilterQuery filter )
242
221
{
243
222
var op = filter . FilterOperation ;
244
223
var concreteType = typeof ( TSource ) ;
@@ -250,27 +229,27 @@ private static IQueryable<TSource> CallGenericWhereMethod<TSource>(IQueryable<TS
250
229
// {model}
251
230
var parameter = Expression . Parameter ( concreteType , "model" ) ;
252
231
// Is relationship attribute
253
- if ( filter . IsAttributeOfRelationship )
232
+ if ( filter . FilteredRelationship != null )
254
233
{
255
- relationProperty = concreteType . GetProperty ( filter . RelationshipAttribute . InternalRelationshipName ) ;
234
+ relationProperty = concreteType . GetProperty ( filter . FilteredRelationship . InternalRelationshipName ) ;
256
235
if ( relationProperty == null )
257
- throw new ArgumentException ( $ "'{ filter . RelationshipAttribute . InternalRelationshipName } ' is not a valid relationship of '{ concreteType } '") ;
236
+ throw new ArgumentException ( $ "'{ filter . FilteredRelationship . InternalRelationshipName } ' is not a valid relationship of '{ concreteType } '") ;
258
237
259
- var relatedType = filter . RelationshipAttribute . Type ;
260
- property = relatedType . GetProperty ( filter . Attribute . InternalAttributeName ) ;
238
+ var relatedType = filter . FilteredRelationship . Type ;
239
+ property = relatedType . GetProperty ( filter . FilteredAttribute . InternalAttributeName ) ;
261
240
if ( property == null )
262
- throw new ArgumentException ( $ "'{ filter . Attribute . InternalAttributeName } ' is not a valid attribute of '{ filter . RelationshipAttribute . InternalRelationshipName } '") ;
241
+ throw new ArgumentException ( $ "'{ filter . FilteredAttribute . InternalAttributeName } ' is not a valid attribute of '{ filter . FilteredRelationship . InternalRelationshipName } '") ;
263
242
264
- var leftRelationship = Expression . PropertyOrField ( parameter , filter . RelationshipAttribute . InternalRelationshipName ) ;
243
+ var leftRelationship = Expression . PropertyOrField ( parameter , filter . FilteredRelationship . InternalRelationshipName ) ;
265
244
// {model.Relationship}
266
245
left = Expression . PropertyOrField ( leftRelationship , property . Name ) ;
267
246
}
268
247
// Is standalone attribute
269
248
else
270
249
{
271
- property = concreteType . GetProperty ( filter . Attribute . InternalAttributeName ) ;
250
+ property = concreteType . GetProperty ( filter . FilteredAttribute . InternalAttributeName ) ;
272
251
if ( property == null )
273
- throw new ArgumentException ( $ "'{ filter . Attribute . InternalAttributeName } ' is not a valid property of '{ concreteType } '") ;
252
+ throw new ArgumentException ( $ "'{ filter . FilteredAttribute . InternalAttributeName } ' is not a valid property of '{ concreteType } '") ;
274
253
275
254
// {model.Id}
276
255
left = Expression . PropertyOrField ( parameter , property . Name ) ;
@@ -300,23 +279,23 @@ private static IQueryable<TSource> CallGenericWhereMethod<TSource>(IQueryable<TS
300
279
}
301
280
}
302
281
303
- private static IQueryable < TSource > CallGenericWhereContainsMethod < TSource > ( IQueryable < TSource > source , BaseAttrQuery filter )
282
+ private static IQueryable < TSource > CallGenericWhereContainsMethod < TSource > ( IQueryable < TSource > source , BaseFilterQuery filter )
304
283
{
305
284
var concreteType = typeof ( TSource ) ;
306
- var property = concreteType . GetProperty ( filter . Attribute . InternalAttributeName ) ;
285
+ var property = concreteType . GetProperty ( filter . FilteredAttribute . InternalAttributeName ) ;
307
286
308
287
try
309
288
{
310
289
var propertyValues = filter . PropertyValue . Split ( QueryConstants . COMMA ) ;
311
290
ParameterExpression entity = Expression . Parameter ( concreteType , "entity" ) ;
312
291
MemberExpression member ;
313
- if ( filter . IsAttributeOfRelationship )
292
+ if ( filter . FilteredRelationship != null )
314
293
{
315
- var relation = Expression . PropertyOrField ( entity , filter . RelationshipAttribute . InternalRelationshipName ) ;
316
- member = Expression . Property ( relation , filter . Attribute . InternalAttributeName ) ;
294
+ var relation = Expression . PropertyOrField ( entity , filter . FilteredRelationship . InternalRelationshipName ) ;
295
+ member = Expression . Property ( relation , filter . FilteredAttribute . InternalAttributeName ) ;
317
296
}
318
297
else
319
- member = Expression . Property ( entity , filter . Attribute . InternalAttributeName ) ;
298
+ member = Expression . Property ( entity , filter . FilteredAttribute . InternalAttributeName ) ;
320
299
321
300
var method = ContainsMethod . MakeGenericMethod ( member . Type ) ;
322
301
var obj = TypeHelper . ConvertListType ( propertyValues , member . Type ) ;
0 commit comments