QueryableExtensions.AverageAsync<TSource> Method (IQueryable<TSource>, Expression<Func<TSource, Nullable<Int64>>>, CancellationToken)

[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]

Asynchronously computes the average of a sequence of nullable Int64 values that is obtained by invoking a projection function on each element of the input sequence.

Namespace:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

Syntax

'Declaration
<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")> _
<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 Long))), _
    cancellationToken As CancellationToken _
) As Task(Of Nullable(Of Double))
'Usage
Dim source As IQueryable(Of TSource)
Dim selector As Expression(Of Func(Of TSource, Nullable(Of Long)))
Dim cancellationToken As CancellationToken 
Dim returnValue As Task(Of Nullable(Of Double))

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

Type Parameters

  • TSource
    The type of the elements of source .

Parameters

Return Value

Type: System.Threading.Tasks.Task<Nullable<Double>>
A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IQueryable<TSource>. When you use instance method syntax to call this method, omit the first parameter. For more information, see https://msdn.microsoft.com/en-us/library/bb384936(v=vs.113) or https://msdn.microsoft.com/en-us/library/bb383977(v=vs.113).

Exceptions

Exception Condition
ArgumentNullException

source or selector is null .

InvalidOperationException

source does not implement IDbAsyncQueryProvider .

Remarks

Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

See Also

Reference

QueryableExtensions Class

AverageAsync Overload

System.Data.Entity Namespace