-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathIExecuteReader.cs
540 lines (482 loc) · 24.9 KB
/
IExecuteReader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
namespace Open.Database.Extensions;
/// <summary>
/// Core non-DB-specific extensions for retrieving data from a command using best practices.
/// </summary>
public static class IExecuteReaderExtensions
{
/// <summary>
/// Iterates a reader on a command with a handler function.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="handler">The handler function for each IDataRecord.</param>
/// <param name="behavior">The behavior to use with the data reader.</param>
public static void IterateReader(this IExecuteReader command, Action<IDataRecord> handler, CommandBehavior behavior = CommandBehavior.Default)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (handler is null) throw new ArgumentNullException(nameof(handler));
Contract.EndContractBlock();
command.ExecuteReader(
reader => reader.ForEach(handler),
behavior | CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates a reader on a command while the handler function returns true.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="handler">The handler function for each IDataRecord.</param>
/// <param name="behavior">The behavior to use with the data reader.</param>
public static void IterateReaderWhile(this IExecuteReader command, Func<IDataRecord, bool> handler, CommandBehavior behavior = CommandBehavior.Default)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (handler is null) throw new ArgumentNullException(nameof(handler));
Contract.EndContractBlock();
command.ExecuteReader(
reader => reader.IterateWhile(handler),
behavior | CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates a reader on a command with a handler function.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="handler">The handler function for each IDataRecord.</param>
/// <param name="behavior">The behavior to use with the data reader.</param>
public static ValueTask IterateReaderAsync(this IExecuteReaderAsync command, Action<IDataRecord> handler, CommandBehavior behavior = CommandBehavior.Default)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (handler is null) throw new ArgumentNullException(nameof(handler));
Contract.EndContractBlock();
return command.ExecuteReaderAsync(
reader =>
{
if (reader is DbDataReader r)
return r.ForEachAsync(handler, command.UseAsyncRead, command.CancellationToken);
reader.ForEach(handler, true, command.CancellationToken);
return new ValueTask();
},
behavior | CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates a reader on a command while the handler function returns true.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="handler">The handler function for each IDataRecord.</param>
/// <param name="behavior">The behavior to use with the data reader.</param>
public static ValueTask IterateReaderWhileAsync(this IExecuteReaderAsync command, Func<IDataRecord, bool> handler, CommandBehavior behavior = CommandBehavior.Default)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (handler is null) throw new ArgumentNullException(nameof(handler));
Contract.EndContractBlock();
return command.ExecuteReaderAsync(
reader =>
{
if (reader is DbDataReader r)
return r.IterateWhileAsync(handler, command.UseAsyncRead, command.CancellationToken);
reader.IterateWhile(handler, true, command.CancellationToken);
return new ValueTask();
},
behavior | CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates a reader on a command while the handler function returns true.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="handler">The handler function for each IDataRecord.</param>
/// <param name="behavior">The behavior to use with the data reader.</param>
public static ValueTask IterateReaderWhileAsync(this IExecuteReaderAsync command, Func<IDataRecord, ValueTask<bool>> handler, CommandBehavior behavior = CommandBehavior.Default)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (handler is null) throw new ArgumentNullException(nameof(handler));
Contract.EndContractBlock();
return command.ExecuteReaderAsync(
reader => reader.IterateWhileAsync(handler, command.CancellationToken),
behavior | CommandBehavior.SingleResult);
}
/// <summary>
/// Executes a reader on a command with a transform function.
/// </summary>
/// <typeparam name="TEntity">The return type of the transform function applied to each record.</typeparam>
/// <typeparam name="TResult">The type returned by the selector.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="transform">The transform function for each IDataRecord.</param>
/// <param name="selector">Provides an IEnumerable<TEntity> to select individual results by.</param>
/// <param name="behavior">The behavior to use with the data reader.</param>
/// <returns>The result of the transform.</returns>
public static TResult IterateReader<TEntity, TResult>(
this IExecuteReader command,
Func<IDataRecord, TEntity> transform,
Func<IEnumerable<TEntity>, TResult> selector, CommandBehavior behavior = CommandBehavior.Default)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => selector(reader.Select(transform)),
behavior | CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates an IDataReader and returns the first result through a transform function. Throws if none.
/// </summary>
/// <typeparam name="T">The return type of the transform function.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="transform">The transform function to process each IDataRecord.</param>
/// <returns>The value from the transform.</returns>
public static T First<T>(this IExecuteReader command, Func<IDataRecord, T> transform)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Select(transform).First(),
CommandBehavior.SingleRow | CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates an IDataReader and returns the first result through a transform function. Returns default(T) if none.
/// </summary>
/// <typeparam name="T">The return type of the transform function.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="transform">The transform function to process each IDataRecord.</param>
/// <returns>The value from the transform.</returns>
public static T? FirstOrDefault<T>(this IExecuteReader command, Func<IDataRecord, T> transform)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Select(transform).FirstOrDefault(),
CommandBehavior.SingleRow | CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates a IDataReader and returns the first result through a transform function.
/// Throws if none or more than one entry.
/// </summary>
/// <typeparam name="T">The return type of the transform function.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="transform">The transform function to process each IDataRecord.</param>
/// <returns>The value from the transform.</returns>
public static T Single<T>(this IExecuteReader command, Func<IDataRecord, T> transform)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Select(transform).Single(),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates an IDataReader and returns the first result through a transform function.
/// Returns default(T) if none.
/// Throws if more than one entry.
/// </summary>
/// <typeparam name="T">The return type of the transform function.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="transform">The transform function to process each IDataRecord.</param>
/// <returns>The value from the transform.</returns>
public static T? SingleOrDefault<T>(this IExecuteReader command, Func<IDataRecord, T> transform)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Select(transform).SingleOrDefault(),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates an IDataReader and returns the first number of results defined by the count.
/// </summary>
/// <typeparam name="T">The return type of the transform function.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="count">The maximum number of records to return.</param>
/// <param name="transform">The transform function to process each IDataRecord.</param>
/// <returns>The results from the transform limited by the take count.</returns>
public static List<T> Take<T>(this IExecuteReader command, int count, Func<IDataRecord, T> transform)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), count, "Cannot be negative.");
Contract.EndContractBlock();
return count == 0 ? [] : command.ExecuteReader(
reader => reader.Select(transform).Take(count).ToList(),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates an IDataReader and skips the first number of results defined by the count.
/// </summary>
/// <typeparam name="T">The return type of the transform function.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="count">The number of records to skip.</param>
/// <param name="transform">The transform function to process each IDataRecord.</param>
/// <returns>The results from the transform after the skip count.</returns>
public static List<T> Skip<T>(this IExecuteReader command, int count, Func<IDataRecord, T> transform)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), count, "Cannot be negative.");
Contract.EndContractBlock();
return command.ExecuteReader(
reader => count == 0
? reader.ToList(transform)
: reader.Select(transform).Skip(count).ToList(),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates an IDataReader and skips by the skip parameter returns the maximum remaining defined by the take parameter.
/// </summary>
/// <typeparam name="T">The return type of the transform function.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="skip">The number of entries to skip before starting to take results.</param>
/// <param name="take">The maximum number of records to return.</param>
/// <param name="transform">The transform function to process each IDataRecord.</param>
/// <returns>The results from the skip, transform and take operation.</returns>
public static List<T> SkipThenTake<T>(this IExecuteReader command, int skip, int take, Func<IDataRecord, T> transform)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
if (skip < 0) throw new ArgumentOutOfRangeException(nameof(skip), skip, "Cannot be negative.");
if (take < 0) throw new ArgumentOutOfRangeException(nameof(take), take, "Cannot be negative.");
Contract.EndContractBlock();
return take == 0
? []
: command.ExecuteReader(
reader => reader.Select(transform).Skip(skip).Take(take).ToList(),
CommandBehavior.SingleResult);
}
/// <summary>
/// Converts all IDataRecords into a list using a transform function.
/// </summary>
/// <typeparam name="T">The expected return type.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="transform">The transform function.</param>
/// <param name="behavior">The command behavior for once the command the reader is complete.</param>
/// <returns>The list of transformed records.</returns>
public static List<T> ToList<T>(this IExecuteReader command, Func<IDataRecord, T> transform, CommandBehavior behavior = CommandBehavior.Default)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Select(transform).ToList(),
behavior | CommandBehavior.SingleResult);
}
/// <summary>
/// Converts all IDataRecords into an array using a transform function.
/// </summary>
/// <typeparam name="T">The expected return type.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="transform">The transform function.</param>
/// <param name="behavior">The command behavior for once the command the reader is complete.</param>
/// <returns>The array of transformed records.</returns>
public static T[] ToArray<T>(this IExecuteReader command, Func<IDataRecord, T> transform, CommandBehavior behavior = CommandBehavior.Default)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Select(transform).ToArray(),
behavior | CommandBehavior.SingleResult);
}
/// <summary>
/// Converts all IDataRecords into an immutable array using a transform function.
/// </summary>
/// <typeparam name="T">The expected return type.</typeparam>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="transform">The transform function.</param>
/// <param name="behavior">The command behavior for once the command the reader is complete.</param>
/// <returns>The array of transformed records.</returns>
public static ImmutableArray<T> ToImmutableArray<T>(this IExecuteReader command, Func<IDataRecord, T> transform, CommandBehavior behavior = CommandBehavior.Default)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (transform is null) throw new ArgumentNullException(nameof(transform));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Select(transform).ToImmutableArray(),
behavior | CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates all records within the first result set using an IDataReader and returns the results.
/// <see cref="DBNull"/> values are left unchanged (retained).
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
public static QueryResultQueue<object[]> Retrieve(this IExecuteReader command)
{
if (command is null) throw new ArgumentNullException(nameof(command));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Retrieve(),
CommandBehavior.SequentialAccess | CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates all records within the current result set using an IDataReader and returns the desired results.
/// <see cref="DBNull"/> values are left unchanged (retained).
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="ordinals">The ordinals to request from the reader for each record.</param>
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
public static QueryResultQueue<object[]> Retrieve(this IExecuteReader command, IEnumerable<int> ordinals)
{
if (command is null) throw new ArgumentNullException(nameof(command));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Retrieve(ordinals),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates all records within the current result set using an IDataReader and returns the desired results.
/// <see cref="DBNull"/> values are left unchanged (retained).
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="n">The first ordinal to include in the request to the reader for each record.</param>
/// <param name="others">The remaining ordinals to request from the reader for each record.</param>
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
public static QueryResultQueue<object[]> Retrieve(this IExecuteReader command, int n, params int[] others)
{
if (command is null) throw new ArgumentNullException(nameof(command));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Retrieve(n, others),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates all records within the first result set using an IDataReader and returns the desired results as a list of Dictionaries containing only the specified column values.
/// <see cref="DBNull"/> values are left unchanged (retained).
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="columnNames">The column names to select.</param>
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
public static QueryResultQueue<object[]> Retrieve(this IExecuteReader command, IEnumerable<string> columnNames)
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (columnNames is null) throw new ArgumentNullException(nameof(columnNames));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Retrieve(columnNames),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates all records within the current result set using an IDataReader and returns the desired results.
/// <see cref="DBNull"/> values are left unchanged (retained).
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <param name="c">The first column name to include in the request to the reader for each record.</param>
/// <param name="others">The remaining column names to request from the reader for each record.</param>
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
public static QueryResultQueue<object[]> Retrieve(this IExecuteReader command, string c, params string[] others)
{
if (command is null) throw new ArgumentNullException(nameof(command));
//if (c is null) throw new ArgumentNullException(nameof(c));
//if (others.Any(e => e is null)) throw new ArgumentNullException(nameof(c));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.Retrieve(c, others),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates each record and attempts to map the fields to type T.
/// Data is temporarily stored (buffered in entirety) in a queue before applying the transform for each iteration.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <typeparam name="T">The model type to map the values to (using reflection).</typeparam>
/// <param name="fieldMappingOverrides">An optional override map of field names to column names where the keys are the property names, and values are the column names.</param>
/// <returns>The enumerable to pull the transformed results from.</returns>
public static IEnumerable<T> Results<T>(this IExecuteReader command, IEnumerable<KeyValuePair<string, string?>> fieldMappingOverrides)
where T : new()
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (fieldMappingOverrides is null) throw new ArgumentNullException(nameof(fieldMappingOverrides));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.ResultsBuffered<T>(fieldMappingOverrides),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates each record and attempts to map the fields to type T.
/// Data is temporarily stored (buffered in entirety) in a queue before applying the transform for each iteration.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <typeparam name="T">The model type to map the values to (using reflection).</typeparam>
/// <param name="fieldMappingOverrides">An optional override map of field names to column names where the keys are the property names, and values are the column names.</param>
/// <returns>The enumerable to pull the transformed results from.</returns>
public static IEnumerable<T> Results<T>(this IExecuteReader command, IEnumerable<(string Field, string? Column)> fieldMappingOverrides)
where T : new()
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (fieldMappingOverrides is null) throw new ArgumentNullException(nameof(fieldMappingOverrides));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.ResultsBuffered<T>(fieldMappingOverrides),
CommandBehavior.SingleResult);
}
/// <summary>
/// Iterates each record and attempts to map the fields to type T.
/// Data is temporarily stored (buffered in entirety) in a queue before applying the transform for each iteration.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <typeparam name="T">The model type to map the values to (using reflection).</typeparam>
/// <param name="fieldMappingOverrides">An optional override map of field names to column names where the keys are the property names, and values are the column names.</param>
/// <returns>The enumerable to pull the transformed results from.</returns>
public static IEnumerable<T> Results<T>(this IExecuteReader command, params (string Field, string? Column)[] fieldMappingOverrides)
where T : new()
{
if (command is null) throw new ArgumentNullException(nameof(command));
if (fieldMappingOverrides is null) throw new ArgumentNullException(nameof(fieldMappingOverrides));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.ResultsBuffered<T>(fieldMappingOverrides),
CommandBehavior.SingleResult);
}
/// <summary>
/// Reads the first column from every record and returns the results as a list..
/// <see cref="DBNull"/> values are converted to null.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <returns>The list of transformed records.</returns>
public static IEnumerable<object?> FirstOrdinalResults(this IExecuteReader command)
{
if (command is null) throw new ArgumentNullException(nameof(command));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.FirstOrdinalResults(),
CommandBehavior.SequentialAccess | CommandBehavior.SingleResult);
}
/// <summary>
/// Reads the first column from every record..
/// <see cref="DBNull"/> values are converted to null.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <returns>The enumerable of casted values.</returns>
public static IEnumerable<T0> FirstOrdinalResults<T0>(this IExecuteReader command)
{
if (command is null) throw new ArgumentNullException(nameof(command));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.FirstOrdinalResults<T0>(),
CommandBehavior.SequentialAccess | CommandBehavior.SingleResult);
}
/// <summary>
/// Imports all data using an IDataReader into a DataTable.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <returns>The resultant DataTable.</returns>
public static DataTable LoadTable(this IExecuteReader command)
{
if (command is null) throw new ArgumentNullException(nameof(command));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.ToDataTable(),
CommandBehavior.SequentialAccess | CommandBehavior.SingleResult);
}
/// <summary>
/// Loads all data from a command through an IDataReader into a DataTables.
/// Calls .NextResult() to check for more results.
/// </summary>
/// <param name="command">The IExecuteReader to iterate.</param>
/// <returns>The resultant list of DataTables.</returns>
public static List<DataTable> LoadTables(this IExecuteReader command)
{
if (command is null) throw new ArgumentNullException(nameof(command));
Contract.EndContractBlock();
return command.ExecuteReader(
reader => reader.ToDataTables(),
CommandBehavior.SequentialAccess);
}
}