Method GetMatchingOrdinals
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
GetMatchingOrdinals(IDataRecord, IEnumerable<string>, bool)
Finds the requested columns that exist in the record, matching names case-insensitively, and returns the mappings as an array.
public static (string Name, int Ordinal)[] GetMatchingOrdinals(this IDataRecord record, IEnumerable<string> columnNames, bool sort = false)
Parameters
recordIDataRecordThe record to query the ordinals from.
columnNamesIEnumerable<string>The requested column names. Names that do not exist in the record are skipped rather than reported.
sortbooltrue to return the mappings in the record's column order; false to return them in the requested order.
Returns
- (string Name, int Ordinal)[]
An array of (name, ordinal) mappings, where each name is the column's actual name in the record.
Remarks
Use OrdinalMapping(IDataRecord, IEnumerable<string>) or GetOrdinalMapping(IDataRecord, IEnumerable<string>, bool) instead when a missing column should be an error.
Exceptions
- ArgumentException
A requested name is null, empty, or white space. It can be thrown when the result is enumerated rather than when this method is called.