@@ -117,31 +117,6 @@ public async Task<ActionResult<Borehole>> GetByIdAsync(int id)
117
117
return Ok ( borehole ) ;
118
118
}
119
119
120
- private IQueryable < Borehole > GetBoreholesWithIncludes ( )
121
- {
122
- return Context . Boreholes . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerColorCodes )
123
- . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerDebrisCodes )
124
- . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerGrainAngularityCodes )
125
- . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerGrainShapeCodes )
126
- . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerOrganicComponentCodes )
127
- . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerUscs3Codes )
128
- . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . LithologicalDescriptions )
129
- . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . FaciesDescriptions )
130
- . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . ChronostratigraphyLayers )
131
- . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . LithostratigraphyLayers )
132
- . Include ( b => b . Completions ) . ThenInclude ( c => c . Casings ) . ThenInclude ( c => c . CasingElements )
133
- . Include ( b => b . Completions ) . ThenInclude ( c => c . Instrumentations )
134
- . Include ( b => b . Completions ) . ThenInclude ( c => c . Backfills )
135
- . Include ( b => b . Sections ) . ThenInclude ( s => s . SectionElements )
136
- . Include ( b => b . Observations )
137
- . Include ( b => b . BoreholeCodelists )
138
- . Include ( b => b . Workflows )
139
- . Include ( b => b . BoreholeFiles )
140
- . Include ( b => b . BoreholeGeometry )
141
- . Include ( b => b . Workgroup )
142
- . Include ( b => b . UpdatedBy ) ;
143
- }
144
-
145
120
/// <summary>
146
121
/// Asynchronously copies a <see cref="Borehole"/>.
147
122
/// </summary>
@@ -170,36 +145,7 @@ public async Task<ActionResult<int>> CopyAsync([Required] int id, [Required] int
170
145
. SingleOrDefaultAsync ( b => b . Id == id )
171
146
. ConfigureAwait ( false ) ;
172
147
173
- if ( borehole == null )
174
- {
175
- return NotFound ( ) ;
176
- }
177
-
178
- if ( borehole . Observations != null )
179
- {
180
- // Include FieldMeasurementResults and HydrotestResults separately since Entity Framework does not support casting in an Include statement
181
- var fieldMeasurements = borehole . Observations . OfType < FieldMeasurement > ( ) . ToList ( ) ;
182
- #pragma warning disable CS8603
183
- // Cannot include null test for fieldMeasurementResults and hydrotestResults since they are not yet loaded
184
- // if there are no fieldMeasurementResults of hydrotestResults the LoadAsync method will be called but have no effect
185
- foreach ( var fieldMeasurement in fieldMeasurements )
186
- {
187
- await Context . Entry ( fieldMeasurement )
188
- . Collection ( f => f . FieldMeasurementResults )
189
- . LoadAsync ( )
190
- . ConfigureAwait ( false ) ;
191
- }
192
-
193
- var hydrotests = borehole . Observations . OfType < Hydrotest > ( ) . ToList ( ) ;
194
- foreach ( var hydrotest in hydrotests )
195
- {
196
- await Context . Entry ( hydrotest )
197
- . Collection ( h => h . HydrotestResults )
198
- . LoadAsync ( )
199
- . ConfigureAwait ( false ) ;
200
- }
201
- #pragma warning restore CS8603
202
- }
148
+ if ( borehole == null ) return NotFound ( ) ;
203
149
204
150
// Set ids of copied entities to zero. Entities with an id of zero are added as new entities to the DB.
205
151
borehole . Id = 0 ;
@@ -293,6 +239,30 @@ await Context.Entry(hydrotest)
293
239
hydrotestResult . Id = 0 ;
294
240
}
295
241
}
242
+
243
+ if ( hydrotest . HydrotestKindCodes != null )
244
+ {
245
+ foreach ( var hydrotestKindCode in hydrotest . HydrotestKindCodes )
246
+ {
247
+ hydrotestKindCode . HydrotestId = 0 ;
248
+ }
249
+ }
250
+
251
+ if ( hydrotest . HydrotestEvaluationMethodCodes != null )
252
+ {
253
+ foreach ( var hydrotestEvaluationMethodCode in hydrotest . HydrotestEvaluationMethodCodes )
254
+ {
255
+ hydrotestEvaluationMethodCode . HydrotestId = 0 ;
256
+ }
257
+ }
258
+
259
+ if ( hydrotest . HydrotestFlowDirectionCodes != null )
260
+ {
261
+ foreach ( var hydrotestFlowDirectionCode in hydrotest . HydrotestFlowDirectionCodes )
262
+ {
263
+ hydrotestFlowDirectionCode . HydrotestId = 0 ;
264
+ }
265
+ }
296
266
}
297
267
}
298
268
@@ -327,4 +297,33 @@ await Context.Entry(hydrotest)
327
297
if ( entity == null ) return default ;
328
298
return await Task . FromResult < int ? > ( entity . Id ) . ConfigureAwait ( false ) ;
329
299
}
300
+
301
+ private IQueryable < Borehole > GetBoreholesWithIncludes ( )
302
+ {
303
+ return Context . Boreholes . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerColorCodes )
304
+ . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerDebrisCodes )
305
+ . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerGrainAngularityCodes )
306
+ . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerGrainShapeCodes )
307
+ . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerOrganicComponentCodes )
308
+ . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . Layers ) . ThenInclude ( l => l . LayerUscs3Codes )
309
+ . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . LithologicalDescriptions )
310
+ . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . FaciesDescriptions )
311
+ . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . ChronostratigraphyLayers )
312
+ . Include ( b => b . Stratigraphies ) . ThenInclude ( s => s . LithostratigraphyLayers )
313
+ . Include ( b => b . Completions ) . ThenInclude ( c => c . Casings ) . ThenInclude ( c => c . CasingElements )
314
+ . Include ( b => b . Completions ) . ThenInclude ( c => c . Instrumentations )
315
+ . Include ( b => b . Completions ) . ThenInclude ( c => c . Backfills )
316
+ . Include ( b => b . Sections ) . ThenInclude ( s => s . SectionElements )
317
+ . Include ( b => b . Observations ) . ThenInclude ( o => ( o as FieldMeasurement ) ! . FieldMeasurementResults )
318
+ . Include ( b => b . Observations ) . ThenInclude ( o => ( o as Hydrotest ) ! . HydrotestResults )
319
+ . Include ( b => b . Observations ) . ThenInclude ( o => ( o as Hydrotest ) ! . HydrotestEvaluationMethodCodes )
320
+ . Include ( b => b . Observations ) . ThenInclude ( o => ( o as Hydrotest ) ! . HydrotestFlowDirectionCodes )
321
+ . Include ( b => b . Observations ) . ThenInclude ( o => ( o as Hydrotest ) ! . HydrotestKindCodes )
322
+ . Include ( b => b . BoreholeCodelists )
323
+ . Include ( b => b . Workflows )
324
+ . Include ( b => b . BoreholeFiles )
325
+ . Include ( b => b . BoreholeGeometry )
326
+ . Include ( b => b . Workgroup )
327
+ . Include ( b => b . UpdatedBy ) ;
328
+ }
330
329
}
0 commit comments