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 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.

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

record IDataRecord

The record to read the values from.

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

record IDataRecord

The record to read the values from.

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

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

record IDataRecord

The record to read the values from.

ordinalMapping ReadOnlySpan<(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

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

record IDataRecord

The record 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 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 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.