EntityFrameworkQueryableExtensions.ToDictionaryAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, CancellationToken)
Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector and an element selector function.
public static System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<TKey,TElement>> ToDictionaryAsync<TSource,TKey,TElement> (this System.Linq.IQueryable<TSource> source, Func<TSource,TKey> keySelector, Func<TSource,TElement> elementSelector, System.Threading.CancellationToken cancellationToken = default);
static member ToDictionaryAsync : System.Linq.IQueryable<'Source> * Func<'Source, 'Key> * Func<'Source, 'Element> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<'Key, 'Element>>
<Extension()>
Public Function ToDictionaryAsync(Of TSource, TKey, TElement) (source As IQueryable(Of TSource), keySelector As Func(Of TSource, TKey), elementSelector As Func(Of TSource, TElement), Optional cancellationToken As CancellationToken = Nothing) As Task(Of Dictionary(Of TKey, TElement))
Type Parameters
- TSource
The type of the elements of source
.
- TKey
The type of the key returned by keySelector
.
- TElement
The type of the value returned by elementSelector
.
Parameters
- source
- IQueryable<TSource>
An IQueryable<T> to create a Dictionary<TKey,TValue> from.
- keySelector
- Func<TSource,TKey>
A function to extract a key from each element.
- elementSelector
- Func<TSource,TElement>
A transform function to produce a result element value from each element.
- cancellationToken
- CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Returns
A task that represents the asynchronous operation.
The task result contains a Dictionary<TKey,TValue> that contains values of type
TElement
selected from the input sequence.
Exceptions
source
or keySelector
or elementSelector
is null
.
If the CancellationToken is canceled.
Remarks
Multiple active operations on the same context instance are not supported. Use await
to ensure that any asynchronous operations have completed before calling another method on this context. See Avoiding DbContext threading issues for more information and examples.
See Querying data with EF Core for more information and examples.
Applies to
ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>, CancellationToken)
Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function, a comparer, and an element selector function.
public static System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<TKey,TElement>> ToDictionaryAsync<TSource,TKey,TElement> (this System.Linq.IQueryable<TSource> source, Func<TSource,TKey> keySelector, Func<TSource,TElement> elementSelector, System.Collections.Generic.IEqualityComparer<TKey> comparer, System.Threading.CancellationToken cancellationToken = default);
public static System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<TKey,TElement>> ToDictionaryAsync<TSource,TKey,TElement> (this System.Linq.IQueryable<TSource> source, Func<TSource,TKey> keySelector, Func<TSource,TElement> elementSelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer, System.Threading.CancellationToken cancellationToken = default);
static member ToDictionaryAsync : System.Linq.IQueryable<'Source> * Func<'Source, 'Key> * Func<'Source, 'Element> * System.Collections.Generic.IEqualityComparer<'Key> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<'Key, 'Element>>
<Extension()>
Public Function ToDictionaryAsync(Of TSource, TKey, TElement) (source As IQueryable(Of TSource), keySelector As Func(Of TSource, TKey), elementSelector As Func(Of TSource, TElement), comparer As IEqualityComparer(Of TKey), Optional cancellationToken As CancellationToken = Nothing) As Task(Of Dictionary(Of TKey, TElement))
Type Parameters
- TSource
The type of the elements of source
.
- TKey
The type of the key returned by keySelector
.
- TElement
The type of the value returned by elementSelector
.
Parameters
- source
- IQueryable<TSource>
An IQueryable<T> to create a Dictionary<TKey,TValue> from.
- keySelector
- Func<TSource,TKey>
A function to extract a key from each element.
- elementSelector
- Func<TSource,TElement>
A transform function to produce a result element value from each element.
- comparer
- IEqualityComparer<TKey>
An IEqualityComparer<T> to compare keys.
- cancellationToken
- CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Returns
A task that represents the asynchronous operation.
The task result contains a Dictionary<TKey,TValue> that contains values of type
TElement
selected from the input sequence.
Exceptions
source
or keySelector
or elementSelector
is null
.
If the CancellationToken is canceled.
Remarks
Multiple active operations on the same context instance are not supported. Use await
to ensure that any asynchronous operations have completed before calling another method on this context. See Avoiding DbContext threading issues for more information and examples.
See Querying data with EF Core for more information and examples.
Applies to
ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, CancellationToken)
Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function.
public static System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<TKey,TSource>> ToDictionaryAsync<TSource,TKey> (this System.Linq.IQueryable<TSource> source, Func<TSource,TKey> keySelector, System.Threading.CancellationToken cancellationToken = default);
static member ToDictionaryAsync : System.Linq.IQueryable<'Source> * Func<'Source, 'Key> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<'Key, 'Source>>
<Extension()>
Public Function ToDictionaryAsync(Of TSource, TKey) (source As IQueryable(Of TSource), keySelector As Func(Of TSource, TKey), Optional cancellationToken As CancellationToken = Nothing) As Task(Of Dictionary(Of TKey, TSource))
Type Parameters
- TSource
The type of the elements of source
.
- TKey
The type of the key returned by keySelector
.
Parameters
- source
- IQueryable<TSource>
An IQueryable<T> to create a Dictionary<TKey,TValue> from.
- keySelector
- Func<TSource,TKey>
A function to extract a key from each element.
- cancellationToken
- CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Returns
A task that represents the asynchronous operation. The task result contains a Dictionary<TKey,TValue> that contains selected keys and values.
Exceptions
source
or keySelector
is null
.
If the CancellationToken is canceled.
Remarks
Multiple active operations on the same context instance are not supported. Use await
to ensure that any asynchronous operations have completed before calling another method on this context. See Avoiding DbContext threading issues for more information and examples.
See Querying data with EF Core for more information and examples.
Applies to
ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>, CancellationToken)
Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function and a comparer.
public static System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<TKey,TSource>> ToDictionaryAsync<TSource,TKey> (this System.Linq.IQueryable<TSource> source, Func<TSource,TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey> comparer, System.Threading.CancellationToken cancellationToken = default);
static member ToDictionaryAsync : System.Linq.IQueryable<'Source> * Func<'Source, 'Key> * System.Collections.Generic.IEqualityComparer<'Key> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Collections.Generic.Dictionary<'Key, 'Source>>
<Extension()>
Public Function ToDictionaryAsync(Of TSource, TKey) (source As IQueryable(Of TSource), keySelector As Func(Of TSource, TKey), comparer As IEqualityComparer(Of TKey), Optional cancellationToken As CancellationToken = Nothing) As Task(Of Dictionary(Of TKey, TSource))
Type Parameters
- TSource
The type of the elements of source
.
- TKey
The type of the key returned by keySelector
.
Parameters
- source
- IQueryable<TSource>
An IQueryable<T> to create a Dictionary<TKey,TValue> from.
- keySelector
- Func<TSource,TKey>
A function to extract a key from each element.
- comparer
- IEqualityComparer<TKey>
An IEqualityComparer<T> to compare keys.
- cancellationToken
- CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Returns
A task that represents the asynchronous operation. The task result contains a Dictionary<TKey,TValue> that contains selected keys and values.
Exceptions
source
or keySelector
is null
.
If the CancellationToken is canceled.
Remarks
Multiple active operations on the same context instance are not supported. Use await
to ensure that any asynchronous operations have completed before calling another method on this context. See Avoiding DbContext threading issues for more information and examples.
See Querying data with EF Core for more information and examples.
Applies to
Entity Framework