QueryableExtensions.ToDictionaryAsync<TSource, TKey> 方法 (IQueryable<TSource>, Func<TSource, TKey>, CancellationToken)

[此頁面專屬於 Entity Framework 第 6 版。最新版本可從 'Entity Framework' NuGet 套件取得。如需 Entity Framework 的詳細資訊,請參閱 msdn.com/data/ef。]

根據指定的索引鍵選取器函式,透過以非同步方式列舉的方式從 IQueryable<T> 建立 Dictionary<TKey, TValue>

命名空間:  System.Data.Entity
組件:  EntityFramework (在 EntityFramework.dll 中)

語法

'宣告
<ExtensionAttribute> _
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
Public Shared Function ToDictionaryAsync(Of TSource, TKey) ( _
    source As IQueryable(Of TSource), _
    keySelector As Func(Of TSource, TKey), _
    cancellationToken As CancellationToken _
) As Task(Of Dictionary(Of TKey, TSource))
'用途
Dim source As IQueryable(Of TSource)
Dim keySelector As Func(Of TSource, TKey)
Dim cancellationToken As CancellationToken 
Dim returnValue As Task(Of Dictionary(Of TKey, TSource))

returnValue = source.ToDictionaryAsync(keySelector, _
    cancellationToken)
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static Task<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(
    this IQueryable<TSource> source,
    Func<TSource, TKey> keySelector,
    CancellationToken cancellationToken
)
[ExtensionAttribute]
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
public:
generic<typename TSource, typename TKey>
static Task<Dictionary<TKey, TSource>^>^ ToDictionaryAsync(
    IQueryable<TSource>^ source, 
    Func<TSource, TKey>^ keySelector, 
    CancellationToken cancellationToken
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
static member ToDictionaryAsync : 
        source:IQueryable<'TSource> * 
        keySelector:Func<'TSource, 'TKey> * 
        cancellationToken:CancellationToken -> Task<Dictionary<'TKey, 'TSource>> 
JScript does not support generic types and methods.

類型參數

  • TSource
    source 之元素的類型。
  • TKey
    由 keySelector 傳回之索引鍵的類型。

參數

  • keySelector
    類型:System.Func<TSource, TKey>
    用來從各個項目擷取索引鍵的函式。

傳回值

類型:System.Threading.Tasks.Task<Dictionary<TKey, TSource>>
表示非同步作業的工作。工作結果包含 Dictionary<TKey, TValue>,其包含選取的索引鍵和值。

使用注意事項

在 Visual Basic 和 C# 中,您可以在任何 IQueryable<TSource> 類型物件中呼叫這個方法以做為執行個體。使用執行個體方法語法呼叫這個方法時,請省略第一個參數。如需詳細資訊,請參閱 https://msdn.microsoft.com/zh-tw/library/bb384936(v=vs.113)https://msdn.microsoft.com/zh-tw/library/bb383977(v=vs.113)

備註

不支援相同內容執行個體上的多個作用中作業。 使用 'await' 確保在此內容上呼叫另一個方法之前,所有非同步作業都已完成。

請參閱

參考

QueryableExtensions 類別

ToDictionaryAsync 多載

System.Data.Entity 命名空間