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

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

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

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

語法

'宣告
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
<ExtensionAttribute> _
Public Shared 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) _
) As Task(Of Dictionary(Of TKey, TElement))
'用途
Dim source As IQueryable(Of TSource)
Dim keySelector As Func(Of TSource, TKey)
Dim elementSelector As Func(Of TSource, TElement)
Dim comparer As IEqualityComparer(Of TKey)
Dim returnValue As Task(Of Dictionary(Of TKey, TElement))

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

類型參數

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

參數

  • keySelector
    類型:System.Func<TSource, TKey>
    用來從各個項目擷取索引鍵的函式。
  • elementSelector
    類型:System.Func<TSource, TElement>
    用來從每個項目產生結果項目值的轉換函式。

傳回值

類型:System.Threading.Tasks.Task<Dictionary<TKey, TElement>>
表示非同步作業的工作。工作結果包含 Dictionary<TKey, TValue>,其包含從輸入序列中選取的類型 TElement 的值。

使用注意事項

在 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 命名空間