@@ -43,7 +43,8 @@ public NoSqlQueryLayerComposer(
43
43
IPaginationContext paginationContext ,
44
44
ITargetedFields targetedFields ,
45
45
IEvaluatedIncludeCache evaluatedIncludeCache ,
46
- ISparseFieldSetCache sparseFieldSetCache ) : base ( constraintProviders , resourceDefinitionAccessor , options , paginationContext , targetedFields , evaluatedIncludeCache , sparseFieldSetCache )
46
+ ISparseFieldSetCache sparseFieldSetCache )
47
+ : base ( constraintProviders , resourceDefinitionAccessor , options , paginationContext , targetedFields , evaluatedIncludeCache , sparseFieldSetCache )
47
48
{
48
49
_constraintProviders = constraintProviders ;
49
50
_targetedFields = targetedFields ;
@@ -89,12 +90,10 @@ public QueryLayer ComposeForGetByIdForNoSql<TId>(TId id, ResourceType primaryRes
89
90
{
90
91
return new QueryLayer ( primaryResourceType )
91
92
{
92
- Filter = new ComparisonExpression (
93
- ComparisonOperator . Equals ,
94
- new ResourceFieldChainExpression (
95
- primaryResourceType . Fields . Single ( field => field . Property . Name == nameof ( IIdentifiable < TId > . Id ) ) ) ,
93
+ Filter = new ComparisonExpression ( ComparisonOperator . Equals ,
94
+ new ResourceFieldChainExpression ( primaryResourceType . Fields . Single ( field => field . Property . Name == nameof ( IIdentifiable < TId > . Id ) ) ) ,
96
95
new LiteralConstantExpression ( id . ToString ( ) ! ) ) ,
97
- Include = IncludeExpression . Empty ,
96
+ Include = IncludeExpression . Empty
98
97
} ;
99
98
}
100
99
@@ -108,37 +107,30 @@ public QueryLayer ComposeForGetByIdForNoSql<TId>(TId id, ResourceType primaryRes
108
107
// Compose a secondary resource filter in the form "equals({propertyName},'{propertyValue}')".
109
108
FilterExpression [ ] secondaryResourceFilterExpressions =
110
109
{
111
- ComposeSecondaryResourceFilter ( requestResourceType , propertyName , propertyValue ) ,
110
+ ComposeSecondaryResourceFilter ( requestResourceType , propertyName , propertyValue )
112
111
} ;
113
112
114
113
// Get the query expressions from the request.
115
- ExpressionInScope [ ] constraints = _constraintProviders
116
- . SelectMany ( provider => provider . GetConstraints ( ) )
117
- . ToArray ( ) ;
114
+ ExpressionInScope [ ] constraints = _constraintProviders . SelectMany ( provider => provider . GetConstraints ( ) ) . ToArray ( ) ;
118
115
119
116
bool IsQueryLayerConstraint ( ExpressionInScope constraint )
120
117
{
121
- return constraint . Expression is not IncludeExpression &&
122
- ( ! isIncluded || ( constraint . Scope is not null &&
123
- constraint . Scope . Fields . Any ( field => field . PublicName == requestResourceType . PublicName ) ) ) ;
118
+ return constraint . Expression is not IncludeExpression && ( ! isIncluded || ( constraint . Scope is not null &&
119
+ constraint . Scope . Fields . Any ( field => field . PublicName == requestResourceType . PublicName ) ) ) ;
124
120
}
125
121
126
- IEnumerable < QueryExpression > requestQueryExpressions = constraints
127
- . Where ( IsQueryLayerConstraint )
128
- . Select ( constraint => constraint . Expression ) ;
122
+ IEnumerable < QueryExpression > requestQueryExpressions = constraints . Where ( IsQueryLayerConstraint ) . Select ( constraint => constraint . Expression ) ;
129
123
130
124
// Combine the secondary resource filter and request query expressions and
131
125
// create the query layer from the combined query expressions.
132
- QueryExpression [ ] queryExpressions = secondaryResourceFilterExpressions
133
- . Concat ( requestQueryExpressions )
134
- . ToArray ( ) ;
126
+ QueryExpression [ ] queryExpressions = secondaryResourceFilterExpressions . Concat ( requestQueryExpressions ) . ToArray ( ) ;
135
127
136
128
var queryLayer = new QueryLayer ( requestResourceType )
137
129
{
138
130
Include = IncludeExpression . Empty ,
139
131
Filter = GetFilter ( queryExpressions , requestResourceType ) ,
140
132
Sort = GetSort ( queryExpressions , requestResourceType ) ,
141
- Pagination = GetPagination ( queryExpressions , requestResourceType ) ,
133
+ Pagination = GetPagination ( queryExpressions , requestResourceType )
142
134
} ;
143
135
144
136
// Retrieve the IncludeExpression from the constraints collection.
@@ -147,46 +139,34 @@ bool IsQueryLayerConstraint(ExpressionInScope constraint)
147
139
// into a single expression.
148
140
IncludeExpression include = isIncluded
149
141
? IncludeExpression . Empty
150
- : constraints
151
- . Select ( constraint => constraint . Expression )
152
- . OfType < IncludeExpression > ( )
153
- . DefaultIfEmpty ( IncludeExpression . Empty )
154
- . Single ( ) ;
142
+ : constraints . Select ( constraint => constraint . Expression ) . OfType < IncludeExpression > ( ) . DefaultIfEmpty ( IncludeExpression . Empty ) . Single ( ) ;
155
143
156
144
return ( queryLayer , include ) ;
157
145
}
158
146
159
- private static FilterExpression ComposeSecondaryResourceFilter (
160
- ResourceType resourceType ,
161
- string propertyName ,
162
- string properyValue )
147
+ private static FilterExpression ComposeSecondaryResourceFilter ( ResourceType resourceType , string propertyName , string properyValue )
163
148
{
164
- return new ComparisonExpression (
165
- ComparisonOperator . Equals ,
149
+ return new ComparisonExpression ( ComparisonOperator . Equals ,
166
150
new ResourceFieldChainExpression ( resourceType . Fields . Single ( field => field . Property . Name == propertyName ) ) ,
167
151
new LiteralConstantExpression ( properyValue ) ) ;
168
152
}
169
153
170
- public ( QueryLayer QueryLayer , IncludeExpression Include ) ComposeForUpdateForNoSql < TId > (
171
- TId id ,
172
- ResourceType primaryResourceType )
154
+ public ( QueryLayer QueryLayer , IncludeExpression Include ) ComposeForUpdateForNoSql < TId > ( TId id , ResourceType primaryResourceType )
173
155
where TId : notnull
174
156
{
175
157
// Create primary layer without an include expression.
176
158
AttrAttribute primaryIdAttribute = GetIdAttribute ( primaryResourceType ) ;
159
+
177
160
QueryLayer primaryLayer = new ( primaryResourceType )
178
161
{
179
162
Include = IncludeExpression . Empty ,
180
- Filter = new ComparisonExpression (
181
- ComparisonOperator . Equals ,
182
- new ResourceFieldChainExpression ( primaryIdAttribute ) ,
183
- new LiteralConstantExpression ( id . ToString ( ) ! ) ) ,
163
+ Filter = new ComparisonExpression ( ComparisonOperator . Equals , new ResourceFieldChainExpression ( primaryIdAttribute ) ,
164
+ new LiteralConstantExpression ( id . ToString ( ) ! ) )
184
165
} ;
185
166
186
167
// Create a separate include expression.
187
168
ImmutableHashSet < IncludeElementExpression > includeElements = _targetedFields . Relationships
188
- . Select ( relationship => new IncludeElementExpression ( relationship ) )
189
- . ToImmutableHashSet ( ) ;
169
+ . Select ( relationship => new IncludeElementExpression ( relationship ) ) . ToImmutableHashSet ( ) ;
190
170
191
171
IncludeExpression include = includeElements . Any ( ) ? new IncludeExpression ( includeElements ) : IncludeExpression . Empty ;
192
172
0 commit comments