Table of Contents

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

record IDataRecord

The record (typically a data reader positioned on a row) to read the values from.

columnMap IEnumerable<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

record or columnMap is 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

record IDataRecord

The record (typically a data reader positioned on a row) to read the values from.

ordinalMapping IEnumerable<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

record or ordinalMapping is 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

record IDataRecord

The record (typically a data reader positioned on a row) to read the values from.

ordinalMapping IReadOnlyList<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

record or ordinalMapping is 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

record IDataRecord

The record (typically a data reader positioned on a row) to read the values from.

ordinalMapping ReadOnlySpan<ColumnOrdinal>

The columns to read.

Returns

Dictionary<string, object>

A new dictionary of values. DBNull values are converted to null.

Exceptions

ArgumentNullException

record is 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

record IDataRecord

The record (typically a data reader positioned on a row) to read the values from.

columnNames IEnumerable<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

record or columnNames is 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

record IDataRecord

The record (typically a data reader positioned on a row) to read the values from.

columnNames IReadOnlyList<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

record or columnNames is 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

record IDataRecord

The record (typically a data reader positioned on a row) to read the values from.

columnNames ReadOnlySpan<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

record is null.

ArgumentException

A name is repeated.

IndexOutOfRangeException

A name is not a column of the record.