@@ -29,60 +29,37 @@ private static MethodInfo ContainsMethod
2929 }
3030 }
3131
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 )
3333 {
3434 if ( sortQueries == null || sortQueries . Count == 0 )
3535 return source ;
3636
37- var orderedEntities = source . Sort ( jsonApiContext , sortQueries [ 0 ] ) ;
37+ var orderedEntities = source . Sort ( sortQueries [ 0 ] ) ;
3838
3939 if ( sortQueries . Count <= 1 )
4040 return orderedEntities ;
4141
4242 for ( var i = 1 ; i < sortQueries . Count ; i ++ )
43- orderedEntities = orderedEntities . Sort ( jsonApiContext , sortQueries [ i ] ) ;
43+ orderedEntities = orderedEntities . Sort ( sortQueries [ i ] ) ;
4444
4545 return orderedEntities ;
4646 }
4747
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 )
4949 {
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 ) ;
6654 }
6755
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 )
6957 {
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+ }
8663
8764 public static IOrderedQueryable < TSource > OrderBy < TSource > ( this IQueryable < TSource > source , string propertyName )
8865 => CallGenericOrderMethod ( source , propertyName , "OrderBy" ) ;
@@ -101,13 +78,15 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
10178 if ( filterQuery == null )
10279 return source ;
10380
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 ) ) ;
10685
107- return source . Filter ( new AttrQuery ( jsonApiContext , filterQuery ) ) ;
86+ return source . Filter ( new AttrFilterQuery ( jsonApiContext , filterQuery ) ) ;
10887 }
10988
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 )
11190 {
11291 if ( filterQuery == null )
11392 return source ;
@@ -238,7 +217,7 @@ private static IOrderedQueryable<TSource> CallGenericOrderMethod<TSource>(IQuery
238217 return ( IOrderedQueryable < TSource > ) result ;
239218 }
240219
241- private static IQueryable < TSource > CallGenericWhereMethod < TSource > ( IQueryable < TSource > source , BaseAttrQuery filter )
220+ private static IQueryable < TSource > CallGenericWhereMethod < TSource > ( IQueryable < TSource > source , BaseFilterQuery filter )
242221 {
243222 var op = filter . FilterOperation ;
244223 var concreteType = typeof ( TSource ) ;
@@ -250,27 +229,27 @@ private static IQueryable<TSource> CallGenericWhereMethod<TSource>(IQueryable<TS
250229 // {model}
251230 var parameter = Expression . Parameter ( concreteType , "model" ) ;
252231 // Is relationship attribute
253- if ( filter . IsAttributeOfRelationship )
232+ if ( filter . FilteredRelationship != null )
254233 {
255- relationProperty = concreteType . GetProperty ( filter . RelationshipAttribute . InternalRelationshipName ) ;
234+ relationProperty = concreteType . GetProperty ( filter . FilteredRelationship . InternalRelationshipName ) ;
256235 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 } '") ;
258237
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 ) ;
261240 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 } '") ;
263242
264- var leftRelationship = Expression . PropertyOrField ( parameter , filter . RelationshipAttribute . InternalRelationshipName ) ;
243+ var leftRelationship = Expression . PropertyOrField ( parameter , filter . FilteredRelationship . InternalRelationshipName ) ;
265244 // {model.Relationship}
266245 left = Expression . PropertyOrField ( leftRelationship , property . Name ) ;
267246 }
268247 // Is standalone attribute
269248 else
270249 {
271- property = concreteType . GetProperty ( filter . Attribute . InternalAttributeName ) ;
250+ property = concreteType . GetProperty ( filter . FilteredAttribute . InternalAttributeName ) ;
272251 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 } '") ;
274253
275254 // {model.Id}
276255 left = Expression . PropertyOrField ( parameter , property . Name ) ;
@@ -300,23 +279,23 @@ private static IQueryable<TSource> CallGenericWhereMethod<TSource>(IQueryable<TS
300279 }
301280 }
302281
303- private static IQueryable < TSource > CallGenericWhereContainsMethod < TSource > ( IQueryable < TSource > source , BaseAttrQuery filter )
282+ private static IQueryable < TSource > CallGenericWhereContainsMethod < TSource > ( IQueryable < TSource > source , BaseFilterQuery filter )
304283 {
305284 var concreteType = typeof ( TSource ) ;
306- var property = concreteType . GetProperty ( filter . Attribute . InternalAttributeName ) ;
285+ var property = concreteType . GetProperty ( filter . FilteredAttribute . InternalAttributeName ) ;
307286
308287 try
309288 {
310289 var propertyValues = filter . PropertyValue . Split ( QueryConstants . COMMA ) ;
311290 ParameterExpression entity = Expression . Parameter ( concreteType , "entity" ) ;
312291 MemberExpression member ;
313- if ( filter . IsAttributeOfRelationship )
292+ if ( filter . FilteredRelationship != null )
314293 {
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 ) ;
317296 }
318297 else
319- member = Expression . Property ( entity , filter . Attribute . InternalAttributeName ) ;
298+ member = Expression . Property ( entity , filter . FilteredAttribute . InternalAttributeName ) ;
320299
321300 var method = ContainsMethod . MakeGenericMethod ( member . Type ) ;
322301 var obj = TypeHelper . ConvertListType ( propertyValues , member . Type ) ;
0 commit comments