@@ -296,9 +296,9 @@ public static string[] GetNames(this IDataRecord record)
296296 /// Returns the (name,ordinal) mapping for current result set.
297297 /// </summary>
298298 /// <param name="record">The reader to get column names from.</param>
299- /// <returns>The array of mappings.</returns>
300- public static ( string Name , int Ordinal ) [ ] GetOrdinalMapping ( this IDataRecord record )
301- => record . GetNames ( ) . Select ( ( n , o ) => ( Name : n , Ordinal : o ) ) . ToArray ( ) ;
299+ /// <returns>An enumerable of the mappings.</returns>
300+ public static IEnumerable < ( string Name , int Ordinal ) > GetOrdinalMapping ( this IDataRecord record )
301+ => record . GetNames ( ) . Select ( ( n , o ) => ( Name : n , Ordinal : o ) ) ;
302302
303303 /// <summary>
304304 /// Returns an array of name to ordinal mappings.
@@ -323,15 +323,14 @@ public static (string Name, int Ordinal)[] GetOrdinalMapping(this IDataRecord re
323323 q = q . OrderBy ( m => m . Ordinal ) ;
324324
325325 return q . ToArray ( ) ;
326-
327326 }
328327 catch ( IndexOutOfRangeException iorex )
329328 {
330329 var mismatch = new HashSet < string > ( cn ) ;
331330 mismatch . ExceptWith ( record . GetNames ( ) ) ;
332331
333332 // Columns not mapped correctly. Report all columns that are mismatched/missing.
334- throw new IndexOutOfRangeException ( $ "Invalid columns: { String . Join ( ", " , mismatch . OrderBy ( c => c ) . ToArray ( ) ) } ", iorex ) ;
333+ throw new IndexOutOfRangeException ( $ "Invalid columns: { string . Join ( ", " , mismatch . OrderBy ( c => c ) . ToArray ( ) ) } ", iorex ) ;
335334 }
336335 }
337336
@@ -349,6 +348,7 @@ public static object[] GetValuesFromOrdinals(this IDataRecord record, params int
349348 var values = new object [ count ] ;
350349 for ( var i = 0 ; i < count ; i ++ )
351350 values [ i ] = record . GetValue ( ordinals [ i ] ) ;
351+
352352 return values ;
353353 }
354354
@@ -378,18 +378,24 @@ public static (string Name, int Ordinal)[] GetMatchingOrdinals(this IDataRecord
378378 var requested = new HashSet < string > ( columnNames ) ;
379379 // Return actual values based upon if their lower-case counterparts exist in the requested.
380380 return actual
381- . Where ( m => columnNames . Contains ( m . Name . ToLowerInvariant ( ) ) )
382- . ToArray ( ) ;
381+ . Where ( m => requested . Contains ( m . Name . ToLowerInvariant ( ) ) )
382+ . ToArray ( ) ;
383383 }
384384 else
385385 {
386386 // Create a map of lower-case keys to acutal.
387387 var actualColumns = actual . ToDictionary ( m => m . Name . ToLowerInvariant ( ) , m => m ) ;
388- return columnNames
389- . Where ( c => actualColumns . ContainsKey ( c ) ) // Select lower case column names if they exist in the dictionary.
390- . Select ( c => actualColumns [ c ] ) // Then select the actual values based upon that key.
391- . ToArray ( ) ;
388+ return columnNames
389+ . Where ( c => actualColumns . ContainsKey ( c ) ) // Select lower case column names if they exist in the dictionary.
390+ . Select ( c => actualColumns [ c ] ) // Then select the actual values based upon that key.
391+ . ToArray ( ) ;
392392 }
393+
394+ /* Note:
395+ * It is not necessary to call .ToArray() because the names are already pulled from the reader,
396+ * and this method could return IEnumerable,
397+ * but it's more common use is to have an array so best to keep it an array.
398+ */
393399 }
394400
395401 /// <summary>
@@ -1459,7 +1465,7 @@ public static IEnumerable<T0> FirstOrdinalResults<T0>(this DbDataReader reader)
14591465 {
14601466 results . Enqueue (
14611467 reader . IsDBNull ( 0 )
1462- ? default ( T0 )
1468+ ? default
14631469 : reader . GetFieldValue < T0 > ( 0 )
14641470 ) ;
14651471 }
@@ -1534,7 +1540,7 @@ public static async Task<IEnumerable<T0>> FirstOrdinalResultsAsync<T0>(this DbDa
15341540 {
15351541 results . Enqueue (
15361542 await reader . IsDBNullAsync ( 0 , t ) . ConfigureAwait ( false )
1537- ? default ( T0 )
1543+ ? default
15381544 : await reader . GetFieldValueAsync < T0 > ( 0 , t ) . ConfigureAwait ( false )
15391545 ) ;
15401546 }
@@ -1545,7 +1551,7 @@ await reader.IsDBNullAsync(0, t).ConfigureAwait(false)
15451551 {
15461552 results . Enqueue (
15471553 reader . IsDBNull ( 0 )
1548- ? default ( T0 )
1554+ ? default
15491555 : reader . GetFieldValue < T0 > ( 0 )
15501556 ) ;
15511557 }
0 commit comments