@@ -116,21 +116,21 @@ private static IQueryable<T> FilterByDefs<T>(
116116 IEnumerable < Overrides < T > . Override < object , object > > overrides
117117 )
118118 {
119+ Expression expBody ;
120+ ParameterExpression [ ] expParams ;
121+
119122 var param = Expression . Parameter ( typeof ( T ) , "x" ) ;
123+ var overridesByFieldName = overrides . ToDictionary ( x => GetFieldName ( x . Selector . Body ) , x => x ) ;
120124
121125 foreach ( var def in filterDefs )
122126 {
123127 var prop = typeof ( T ) . GetProperty ( def . Name )
124128 ?? throw new ArgumentException ( $ "Property { def . Name } does not exist in queryable object of { typeof ( T ) . Name } !") ;
125129
126- Expression expBody = Expression . MakeMemberAccess ( param , prop ) ;
127- ParameterExpression [ ] expParams = [ param] ;
128-
129- var or = overrides . FirstOrDefault (
130- x => GetFieldName ( x . Selector . Body ) == def . Name
131- ) ;
130+ expBody = Expression . MakeMemberAccess ( param , prop ) ;
131+ expParams = [ param] ;
132132
133- if ( or != null )
133+ if ( overridesByFieldName . TryGetValue ( def . Name , out var or ) )
134134 {
135135 expBody = GetTrueExpression ( or . ValueReplace . Body ) ;
136136 expParams = [ .. or . ValueReplace . Parameters ] ;
@@ -162,21 +162,21 @@ private static IQueryable<T> OrderByDefs<T>(
162162 IEnumerable < Overrides < T > . Override < object , object > > overrides
163163 )
164164 {
165+ Expression expBody ;
166+ ParameterExpression [ ] expParams ;
167+
165168 var param = Expression . Parameter ( typeof ( T ) , "x" ) ;
169+ var overridesByFieldName = overrides . ToDictionary ( x => GetFieldName ( x . Selector . Body ) , x => x ) ;
166170
167171 foreach ( var def in orderDefs )
168172 {
169173 var prop = typeof ( T ) . GetProperty ( def . Name )
170174 ?? throw new ArgumentException ( $ "Property { def . Name } does not exist in queryable object of { typeof ( T ) . Name } !") ;
171175
172- Expression expBody = Expression . Property ( param , prop ) ;
173- ParameterExpression [ ] expParams = [ param] ;
174-
175- var or = overrides . FirstOrDefault (
176- x => GetFieldName ( x . Selector . Body ) == def . Name
177- ) ;
176+ expBody = Expression . Property ( param , prop ) ;
177+ expParams = [ param] ;
178178
179- if ( or != null )
179+ if ( overridesByFieldName . TryGetValue ( def . Name , out var or ) )
180180 {
181181 expBody = GetTrueExpression ( or . ValueReplace . Body ) ;
182182 expParams = [ .. or . ValueReplace . Parameters ] ;
0 commit comments