EntityFrameworkQueryableExtensions.ToDictionaryAsync 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, CancellationToken)
通过根据指定的键选择器和元素选择器函数异步枚举它来创建一Dictionary<TKey,TValue>IQueryable<T>个。
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))
类型参数
- TSource
的元素 source的类型。
- TKey
返回 keySelector的键的类型。
- TElement
返回 elementSelector的值的类型。
参数
- source
- IQueryable<TSource>
要从中创建的一 IQueryable<T> 个 Dictionary<TKey,TValue> 。
- keySelector
- Func<TSource,TKey>
用于从每个元素中提取键的函数。
- elementSelector
- Func<TSource,TElement>
一个转换函数,用于从每个元素生成结果元素值。
- cancellationToken
- CancellationToken
等待任务完成时观察的 A CancellationToken 。
返回
表示异步操作的任务。
任务结果包含一个 Dictionary<TKey,TValue> 值,其中包含从输入序列中选择的类型 TElement 值。
例外
source 或 keySelector 为 elementSelectornull.
如果取消了该操作 CancellationToken 。
注解
不支持对同一上下文实例执行多个活动操作。 用于 await 确保在在此上下文上调用其他方法之前已完成任何异步操作。 有关详细信息和示例,请参阅 避免 DbContext 线程问题 。
有关详细信息和示例,请参阅 使用 EF Core 查询数据 。
适用于
ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>, CancellationToken)
Dictionary<TKey,TValue> IQueryable<T>通过根据指定的键选择器函数、比较器和元素选择器函数异步枚举它来创建一个。
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))
类型参数
- TSource
的元素 source的类型。
- TKey
返回 keySelector的键的类型。
- TElement
返回 elementSelector的值的类型。
参数
- source
- IQueryable<TSource>
要从中创建的一 IQueryable<T> 个 Dictionary<TKey,TValue> 。
- keySelector
- Func<TSource,TKey>
用于从每个元素中提取键的函数。
- elementSelector
- Func<TSource,TElement>
一个转换函数,用于从每个元素生成结果元素值。
- comparer
- IEqualityComparer<TKey>
要比较键的一个 IEqualityComparer<T> 。
- cancellationToken
- CancellationToken
等待任务完成时观察的 A CancellationToken 。
返回
表示异步操作的任务。
任务结果包含一个 Dictionary<TKey,TValue> 值,其中包含从输入序列中选择的类型 TElement 值。
例外
source 或 keySelector 为 elementSelectornull.
如果取消了该操作 CancellationToken 。
注解
不支持对同一上下文实例执行多个活动操作。 用于 await 确保在在此上下文上调用其他方法之前已完成任何异步操作。 有关详细信息和示例,请参阅 避免 DbContext 线程问题 。
有关详细信息和示例,请参阅 使用 EF Core 查询数据 。
适用于
ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, CancellationToken)
通过根据指定的键选择器函数异步枚举它来创建一个Dictionary<TKey,TValue>IQueryable<T>。
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))
类型参数
- TSource
的元素 source的类型。
- TKey
返回 keySelector的键的类型。
参数
- source
- IQueryable<TSource>
要从中创建的一 IQueryable<T> 个 Dictionary<TKey,TValue> 。
- keySelector
- Func<TSource,TKey>
用于从每个元素中提取键的函数。
- cancellationToken
- CancellationToken
等待任务完成时观察的 A CancellationToken 。
返回
表示异步操作的任务。 任务结果包含一个 Dictionary<TKey,TValue> 包含所选键和值的键。
例外
source 或 keySelector 为 null.
如果取消了该操作 CancellationToken 。
注解
不支持对同一上下文实例执行多个活动操作。 用于 await 确保在在此上下文上调用其他方法之前已完成任何异步操作。 有关详细信息和示例,请参阅 避免 DbContext 线程问题 。
有关详细信息和示例,请参阅 使用 EF Core 查询数据 。
适用于
ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>, CancellationToken)
通过根据指定的键选择器函数和比较器异步枚举它来创建一Dictionary<TKey,TValue>IQueryable<T>个。
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))
类型参数
- TSource
的元素 source的类型。
- TKey
返回 keySelector的键的类型。
参数
- source
- IQueryable<TSource>
要从中创建的一 IQueryable<T> 个 Dictionary<TKey,TValue> 。
- keySelector
- Func<TSource,TKey>
用于从每个元素中提取键的函数。
- comparer
- IEqualityComparer<TKey>
要比较键的一个 IEqualityComparer<T> 。
- cancellationToken
- CancellationToken
等待任务完成时观察的 A CancellationToken 。
返回
表示异步操作的任务。 任务结果包含一个 Dictionary<TKey,TValue> 包含所选键和值的键。
例外
source 或 keySelector 为 null.
如果取消了该操作 CancellationToken 。
注解
不支持对同一上下文实例执行多个活动操作。 用于 await 确保在在此上下文上调用其他方法之前已完成任何异步操作。 有关详细信息和示例,请参阅 避免 DbContext 线程问题 。
有关详细信息和示例,请参阅 使用 EF Core 查询数据 。