QueryableExtensions.AverageAsync<TSource> 方法 (IQueryable<TSource>, Expression<Func<TSource, Nullable<Decimal>>>)

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

非同步計算在輸入序列中各元素上叫用投影函式後所取得之可為 Null 之 Decimal 值序列的平均值。

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

語法

'宣告
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
<ExtensionAttribute> _
Public Shared Function AverageAsync(Of TSource) ( _
    source As IQueryable(Of TSource), _
    selector As Expression(Of Func(Of TSource, Nullable(Of Decimal))) _
) As Task(Of Nullable(Of Decimal))
'用途
Dim source As IQueryable(Of TSource)
Dim selector As Expression(Of Func(Of TSource, Nullable(Of Decimal)))
Dim returnValue As Task(Of Nullable(Of Decimal))

returnValue = source.AverageAsync(selector)
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static Task<Nullable<decimal>> AverageAsync<TSource>(
    this IQueryable<TSource> source,
    Expression<Func<TSource, Nullable<decimal>>> selector
)
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
[ExtensionAttribute]
public:
generic<typename TSource>
static Task<Nullable<Decimal>>^ AverageAsync(
    IQueryable<TSource>^ source, 
    Expression<Func<TSource, Nullable<Decimal>>^>^ selector
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
static member AverageAsync : 
        source:IQueryable<'TSource> * 
        selector:Expression<Func<'TSource, Nullable<decimal>>> -> Task<Nullable<decimal>> 
JScript does not support generic types and methods.

類型參數

  • TSource
    source 之元素的類型。

參數

傳回值

類型:System.Threading.Tasks.Task<Nullable<Decimal>>
表示非同步作業的工作。工作結果包含值序列的平均值。

使用注意事項

在 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)

例外狀況

例外狀況 條件
ArgumentNullException

source 或 selector 為 null。

InvalidOperationException

source 不會實作 IDbAsyncQueryProvider

備註

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

請參閱

參考

QueryableExtensions 類別

AverageAsync 多載

System.Data.Entity 命名空間