DbRawSqlQuery<TElement>.ToDictionaryAsync<TKey> 方法 (Func<TElement, TKey>, IEqualityComparer<TKey>, CancellationToken)
[本页针对的是实体框架版本 6。最新版本以“实体框架”NuGet 包的形式提供。有关实体框架的更多信息,请参见 msdn.com/data/ef。]
通过异步枚举它根据指定的键选择器函数和比较器从查询创建 Dictionary<TKey, TValue>。
命名空间: System.Data.Entity.Infrastructure
程序集: EntityFramework(在 EntityFramework.dll 中)
语法
声明
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
Public Function ToDictionaryAsync(Of TKey) ( _
keySelector As Func(Of TElement, TKey), _
comparer As IEqualityComparer(Of TKey), _
cancellationToken As CancellationToken _
) As Task(Of Dictionary(Of TKey, TElement))
用法
Dim instance As DbRawSqlQuery
Dim keySelector As Func(Of TElement, TKey)
Dim comparer As IEqualityComparer(Of TKey)
Dim cancellationToken As CancellationToken
Dim returnValue As Task(Of Dictionary(Of TKey, TElement))
returnValue = instance.ToDictionaryAsync(keySelector, _
comparer, cancellationToken)
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TKey>(
Func<TElement, TKey> keySelector,
IEqualityComparer<TKey> comparer,
CancellationToken cancellationToken
)
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
public:
generic<typename TKey>
Task<Dictionary<TKey, TElement>^>^ ToDictionaryAsync(
Func<TElement, TKey>^ keySelector,
IEqualityComparer<TKey>^ comparer,
CancellationToken cancellationToken
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
member ToDictionaryAsync :
keySelector:Func<'TElement, 'TKey> *
comparer:IEqualityComparer<'TKey> *
cancellationToken:CancellationToken -> Task<Dictionary<'TKey, 'TElement>>
JScript does not support generic types and methods.
类型参数
- TKey
keySelector 返回的键类型。
参数
- keySelector
类型:System.Func<TElement, TKey>
用于从每个元素中提取键的函数。
- comparer
类型:System.Collections.Generic.IEqualityComparer<TKey>
一个用于比较键的 IEqualityComparer<T>。
- cancellationToken
类型:System.Threading.CancellationToken
等待任务完成期间要观察的 CancellationToken。
返回值
类型:System.Threading.Tasks.Task<Dictionary<TKey, TElement>>
表示异步操作的任务。任务结果包含一个 Dictionary<TKey, TValue>,后者包含所选的键和值。
备注
不支持对同一上下文实例执行多个活动操作。 使用“await”以确保在对此上下文调用另一个方法前完成了所有异步操作。