DbRawSqlQuery<TElement>.ToDictionaryAsync<TKey, TResult> 方法 (Func<TElement, TKey>, Func<TElement, TResult>, 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, TResult) ( _
keySelector As Func(Of TElement, TKey), _
elementSelector As Func(Of TElement, TResult), _
comparer As IEqualityComparer(Of TKey), _
cancellationToken As CancellationToken _
) As Task(Of Dictionary(Of TKey, TResult))
用法
Dim instance As DbRawSqlQuery
Dim keySelector As Func(Of TElement, TKey)
Dim elementSelector As Func(Of TElement, TResult)
Dim comparer As IEqualityComparer(Of TKey)
Dim cancellationToken As CancellationToken
Dim returnValue As Task(Of Dictionary(Of TKey, TResult))
returnValue = instance.ToDictionaryAsync(keySelector, _
elementSelector, comparer, cancellationToken)
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public Task<Dictionary<TKey, TResult>> ToDictionaryAsync<TKey, TResult>(
Func<TElement, TKey> keySelector,
Func<TElement, TResult> elementSelector,
IEqualityComparer<TKey> comparer,
CancellationToken cancellationToken
)
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
public:
generic<typename TKey, typename TResult>
Task<Dictionary<TKey, TResult>^>^ ToDictionaryAsync(
Func<TElement, TKey>^ keySelector,
Func<TElement, TResult>^ elementSelector,
IEqualityComparer<TKey>^ comparer,
CancellationToken cancellationToken
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
member ToDictionaryAsync :
keySelector:Func<'TElement, 'TKey> *
elementSelector:Func<'TElement, 'TResult> *
comparer:IEqualityComparer<'TKey> *
cancellationToken:CancellationToken -> Task<Dictionary<'TKey, 'TResult>>
JScript does not support generic types and methods.
类型参数
- TKey
keySelector 返回的键类型。
- TResult
elementSelector 返回的值的类型。
参数
- keySelector
类型:System.Func<TElement, TKey>
用于从每个元素中提取键的函数。
- elementSelector
类型:System.Func<TElement, TResult>
用于从每个元素产生结果元素值的转换函数。
- comparer
类型:System.Collections.Generic.IEqualityComparer<TKey>
一个用于比较键的 IEqualityComparer<T>。
- cancellationToken
类型:System.Threading.CancellationToken
等待任务完成期间要观察的 CancellationToken。
返回值
类型:System.Threading.Tasks.Task<Dictionary<TKey, TResult>>
表示异步操作的任务。任务结果包含一个 Dictionary<TKey, TValue>,后者包含从输入序列选择的类型 TResult 的值。
备注
不支持对同一上下文实例执行多个活动操作。 使用“await”以确保在对此上下文调用另一个方法前完成了所有异步操作。