Method ToDictionary
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
ToDictionary(IDataRecord, IEnumerable<KeyValuePair<int, string>>)
Reads the specified columns of the current row into a dictionary keyed by the supplied names.
public static Dictionary<string, object?> ToDictionary(this IDataRecord record, IEnumerable<KeyValuePair<int, string>> columnMap)
Parameters
recordIDataRecordThe record (typically a data reader positioned on a row) to read the values from.
columnMapIEnumerable<KeyValuePair<int, string>>The ordinals to read, paired with the key to store each value under.
Returns
- Dictionary<string, object>
A new dictionary of values. DBNull values are converted to null.
Exceptions
- ArgumentException
Two entries have the same key.
- ArgumentNullException
recordorcolumnMapis null.
ToDictionary(IDataRecord, IEnumerable<ColumnOrdinal>)
Reads the specified columns of the current row into a dictionary keyed by column name.
public static Dictionary<string, object?> ToDictionary(this IDataRecord record, IEnumerable<ColumnOrdinal> ordinalMapping)
Parameters
recordIDataRecordThe record (typically a data reader positioned on a row) to read the values from.
ordinalMappingIEnumerable<ColumnOrdinal>The columns to read, as produced by OrdinalMapping(IDataRecord).
Returns
- Dictionary<string, object>
A new dictionary of values. DBNull values are converted to null.
Exceptions
- ArgumentException
Two entries have the same name, or an entry is a default ColumnOrdinal.
- ArgumentNullException
recordorordinalMappingis null.
ToDictionary(IDataRecord, IReadOnlyList<ColumnOrdinal>)
Reads the specified columns of the current row into a dictionary keyed by column name.
public static Dictionary<string, object?> ToDictionary(this IDataRecord record, IReadOnlyList<ColumnOrdinal> ordinalMapping)
Parameters
recordIDataRecordThe record (typically a data reader positioned on a row) to read the values from.
ordinalMappingIReadOnlyList<ColumnOrdinal>The columns to read, as produced by GetOrdinalMapping(IDataRecord, IEnumerable<string>, bool).
Returns
- Dictionary<string, object>
A new dictionary of values. DBNull values are converted to null.
Exceptions
- ArgumentNullException
recordorordinalMappingis null.- ArgumentException
Two entries have the same name, or an entry is a default ColumnOrdinal.
ToDictionary(IDataRecord, ReadOnlySpan<ColumnOrdinal>)
Reads the specified columns of the current row into a dictionary keyed by column name.
public static Dictionary<string, object?> ToDictionary(this IDataRecord record, ReadOnlySpan<ColumnOrdinal> ordinalMapping)
Parameters
recordIDataRecordThe record (typically a data reader positioned on a row) to read the values from.
ordinalMappingReadOnlySpan<ColumnOrdinal>The columns to read.
Returns
- Dictionary<string, object>
A new dictionary of values. DBNull values are converted to null.
Exceptions
- ArgumentNullException
recordis null.- ArgumentException
Two entries have the same name, or an entry is a default ColumnOrdinal.
ToDictionary(IDataRecord, IEnumerable<string>)
Reads the named columns of the current row into a dictionary keyed by column name.
public static Dictionary<string, object?> ToDictionary(this IDataRecord record, IEnumerable<string> columnNames)
Parameters
recordIDataRecordThe record (typically a data reader positioned on a row) to read the values from.
columnNamesIEnumerable<string>The names of the columns to read. Each name is looked up with the record's string indexer.
Returns
- Dictionary<string, object>
A new dictionary of values. DBNull values are converted to null.
Exceptions
- ArgumentNullException
recordorcolumnNamesis null.- ArgumentException
A name is repeated.
- IndexOutOfRangeException
A name is not a column of the record.
ToDictionary(IDataRecord, IReadOnlyList<string>)
Reads the named columns of the current row into a dictionary keyed by column name.
public static Dictionary<string, object?> ToDictionary(this IDataRecord record, IReadOnlyList<string> columnNames)
Parameters
recordIDataRecordThe record (typically a data reader positioned on a row) to read the values from.
columnNamesIReadOnlyList<string>The names of the columns to read. Each name is looked up with the record's string indexer.
Returns
- Dictionary<string, object>
A new dictionary of values. DBNull values are converted to null.
Exceptions
- ArgumentNullException
recordorcolumnNamesis null.- ArgumentException
A name is repeated.
- IndexOutOfRangeException
A name is not a column of the record.
ToDictionary(IDataRecord, ReadOnlySpan<string>)
Reads the named columns of the current row into a dictionary keyed by column name.
public static Dictionary<string, object?> ToDictionary(this IDataRecord record, ReadOnlySpan<string> columnNames)
Parameters
recordIDataRecordThe record (typically a data reader positioned on a row) to read the values from.
columnNamesReadOnlySpan<string>The names of the columns to read. Each name is looked up with the record's string indexer.
Returns
- Dictionary<string, object>
A new dictionary of values. DBNull values are converted to null.
Exceptions
- ArgumentNullException
recordis null.- ArgumentException
A name is repeated.
- IndexOutOfRangeException
A name is not a column of the record.