Table of Contents

Method ToDictionary

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.Core.dll

ToDictionary<T, TKey>(IMappedQuery<T>, Func<T, TKey>, IEqualityComparer<TKey>?)

Reads every mapped row into a new Dictionary<TKey, TValue>, keyed by keySelector.

public static Dictionary<TKey, T> ToDictionary<T, TKey>(this IMappedQuery<T> query, Func<T, TKey> keySelector, IEqualityComparer<TKey>? comparer = null) where TKey : notnull

Parameters

query IMappedQuery<T>

The query to execute.

keySelector Func<T, TKey>

Produces the key for each mapped row.

comparer IEqualityComparer<TKey>

The comparer for the keys, or null to use the default comparer.

Returns

Dictionary<TKey, T>

A dictionary of all the rows. It is empty if there are no rows.

Type Parameters

T

The type each row is mapped to.

TKey

The type of the dictionary key.

Remarks

All rows are buffered in memory before the call returns. Use Read(Action<IEnumerable<T>>) to process very large results as a stream.

Exceptions

ArgumentNullException

keySelector is null.

ArgumentException

Two rows produce the same key.

See Also