次の方法で共有


QueryableExtensions.AverageAsync<TSource> メソッド (IQueryable<TSource>, Expression<Func<TSource, Single>>, CancellationToken)

[このページは、Entity Framework 6 に関するページです。最新バージョンは、'Entity Framework' NuGet パッケージとして入手できます。Entity Framework の詳細については、msdn.com/data/ef を参照してください。]

入力シーケンスの各要素に対して射影関数を呼び出して取得する Single 値のシーケンスの平均を非同期に計算します。

名前空間:  System.Data.Entity
アセンブリ:  EntityFramework (EntityFramework.dll 内)

構文

'宣言
<ExtensionAttribute> _
<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")> _
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
Public Shared Function AverageAsync(Of TSource) ( _
    source As IQueryable(Of TSource), _
    selector As Expression(Of Func(Of TSource, Single)), _
    cancellationToken As CancellationToken _
) As Task(Of Single)
'使用
Dim source As IQueryable(Of TSource)
Dim selector As Expression(Of Func(Of TSource, Single))
Dim cancellationToken As CancellationToken 
Dim returnValue As Task(Of Single)

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

型パラメーター

  • TSource
    source の要素の型。

パラメーター

  • source
    型 : System.Linq.IQueryable<TSource>
    平均値を計算する対象となる値のシーケンス。

戻り値

型 : System.Threading.Tasks.Task<Single>
非同期操作を表すタスク。タスクの結果には、値のシーケンスの平均が示されます。

使用上の注意

Visual Basic および Visual C# では、このメソッドを、IQueryable<TSource> 型のオブジェクトのインスタンス メソッドとして呼び出すことができます。インスタンス メソッド構文を使用してこのメソッドを呼び出す場合は、最初のパラメーターを省略します。詳細については、「https://msdn.microsoft.com/ja-jp/library/bb384936(v=vs.113)」または「https://msdn.microsoft.com/ja-jp/library/bb383977(v=vs.113)」を参照してください。

例外

例外 状態
ArgumentNullException

source または selector が null です。

InvalidOperationException

source は IDbAsyncQueryProvider を実装しません。

InvalidOperationException

source に要素が含まれていません。

解説

同じコンテキスト インスタンスに対する複数のアクティブ操作はサポートされません。 このコンテキストで別のメソッドを呼び出す前に、非同期操作が完了したことを確認するために await を使用します。

参照

参照

QueryableExtensions クラス

AverageAsync オーバーロード

System.Data.Entity 名前空間