EntityFrameworkQueryableExtensions.ToDictionaryAsync 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, CancellationToken)
透過非同步列舉,依照指定的鍵選擇器與元素選擇函式,從 建立 a 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 在等待任務完成時觀察。
傳回
一個代表非同步操作的任務。
任務結果包含 a Dictionary<TKey,TValue> ,該 包含從輸入序列中選擇的值 TElement 。
例外狀況
source或keySelectorelementSelector是 null。
備註
不支援在同一上下文實例上進行多個主動操作。 在此上下文中,請用 await 以確認所有非同步操作已完成,然後再呼叫其他方法。 更多資訊與範例請參見 「避免 DbContext 執行緒問題 」。
更多資訊與範例請參閱使用 EF Core 查詢資料 。
適用於
ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>, CancellationToken)
透過非同步列舉,依照指定的鍵選擇函數、比較器及元素選擇函式,從 和 IQueryable<T> 建立 aDictionary<TKey,TValue>。
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 在等待任務完成時觀察。
傳回
一個代表非同步操作的任務。
任務結果包含 a Dictionary<TKey,TValue> ,該 包含從輸入序列中選擇的值 TElement 。
例外狀況
source或keySelectorelementSelector是 null。
備註
不支援在同一上下文實例上進行多個主動操作。 在此上下文中,請用 await 以確認所有非同步操作已完成,然後再呼叫其他方法。 更多資訊與範例請參見 「避免 DbContext 執行緒問題 」。
更多資訊與範例請參閱使用 EF Core 查詢資料 。
適用於
ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, CancellationToken)
透過非同步列舉,依照指定的鍵選擇函式從 中IQueryable<T>建立 aDictionary<TKey,TValue>。
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。
備註
不支援在同一上下文實例上進行多個主動操作。 在此上下文中,請用 await 以確認所有非同步操作已完成,然後再呼叫其他方法。 更多資訊與範例請參見 「避免 DbContext 執行緒問題 」。
更多資訊與範例請參閱使用 EF Core 查詢資料 。
適用於
ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>, CancellationToken)
透過非同步列舉,根據指定的金鑰選擇函式與比較器,從 和 IQueryable<T> 建立 。Dictionary<TKey,TValue>
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。
備註
不支援在同一上下文實例上進行多個主動操作。 在此上下文中,請用 await 以確認所有非同步操作已完成,然後再呼叫其他方法。 更多資訊與範例請參見 「避免 DbContext 執行緒問題 」。
更多資訊與範例請參閱使用 EF Core 查詢資料 。