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 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.
ToDictionary(IDataRecord, IEnumerable<(string Name, int Ordinal)>)
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<(string Name, int Ordinal)> ordinalMapping)
Parameters
recordIDataRecordThe record to read the values from.
ordinalMappingIEnumerable<(string Name, int Ordinal)>The (name, ordinal) pairs 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.
ToDictionary(IDataRecord, IReadOnlyList<(string Name, int Ordinal)>)
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<(string Name, int Ordinal)> ordinalMapping)
Parameters
recordIDataRecordThe record to read the values from.
ordinalMappingIReadOnlyList<(string Name, int Ordinal)>The (name, ordinal) pairs 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.
ToDictionary(IDataRecord, ReadOnlySpan<(string Name, int Ordinal)>)
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<(string Name, int Ordinal)> ordinalMapping)
Parameters
recordIDataRecordThe record to read the values from.
ordinalMappingReadOnlySpan<(string Name, int Ordinal)>The (name, ordinal) pairs 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.
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 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 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 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.