Table of Contents

Method ToDictionaryAsync

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

ToDictionaryAsync<TKey>(Func<T, TKey>, IEqualityComparer<TKey>?, CancellationToken)

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

public ValueTask<Dictionary<TKey, T>> ToDictionaryAsync<TKey>(Func<T, TKey> keySelector, IEqualityComparer<TKey>? comparer = null, CancellationToken cancellationToken = default) where TKey : notnull

Parameters

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.

cancellationToken CancellationToken

Cancels the operation. When it cannot be canceled, the cancellation token set on the underlying command applies.

Returns

ValueTask<Dictionary<TKey, T>>

A task that produces a dictionary of all the rows.

Type Parameters

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

OperationCanceledException

The operation was canceled.

ArgumentNullException

keySelector is null.

ArgumentException

Two rows produce the same key.

See Also