QueryableExtensions.CountAsync<TSource> Method (IQueryable<TSource>)
[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 returns the number of elements in a sequence.
Namespace: System.Data.Entity
Assembly: EntityFramework (in EntityFramework.dll)
Syntax
'Declaration
<ExtensionAttribute> _
Public Shared Function CountAsync(Of TSource) ( _
source As IQueryable(Of TSource) _
) As Task(Of Integer)
'Usage
Dim source As IQueryable(Of TSource)
Dim returnValue As Task(Of Integer)
returnValue = source.CountAsync()
public static Task<int> CountAsync<TSource>(
this IQueryable<TSource> source
)
[ExtensionAttribute]
public:
generic<typename TSource>
static Task<int>^ CountAsync(
IQueryable<TSource>^ source
)
static member CountAsync :
source:IQueryable<'TSource> -> Task<int>
JScript does not support generic types and methods.
Type Parameters
- TSource
The type of the elements of source.
Parameters
- source
Type: System.Linq.IQueryable<TSource>
An IQueryable<T> that contains the elements to be counted.
Return Value
Type: System.Threading.Tasks.Task<Int32>
A task that represents the asynchronous operation. The task result contains the number of elements in the input sequence.
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 is null . |
InvalidOperationException | source does not implement IDbAsyncQueryProvider . |
OverflowException | The number of elements in source is larger than MaxValue. |
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.