QueryableExtensions.CountAsync Method

 

Asynchronously returns the number of elements in a sequence.

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

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticCountAsync<TSource>(IQueryable<TSource>)

Asynchronously returns the number of elements in a sequence.

System_CAPS_pubmethodSystem_CAPS_staticCountAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the number of elements in a sequence.

System_CAPS_pubmethodSystem_CAPS_staticCountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, Boolean>>)

Asynchronously returns the number of elements in a sequence that satisfy a condition.

System_CAPS_pubmethodSystem_CAPS_staticCountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, Boolean>>, CancellationToken)

Asynchronously returns the number of elements in a sequence that satisfy a condition.


QueryableExtensions.CountAsync<TSource> Method (IQueryable<TSource>)

Asynchronously returns the number of elements in a sequence.

public static Task<int> CountAsync<TSource>(
	this IQueryable<TSource> 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.

Type Parameters

TSource

The type of the elements of source.

Exception Condition
ArgumentNullException

source is null .

InvalidOperationException

source does not implement IDbAsyncQueryProvider .

OverflowException

The number of elements in source is larger than MaxValue.

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.


QueryableExtensions.CountAsync<TSource> Method (IQueryable<TSource>, CancellationToken)

Asynchronously returns the number of elements in a sequence.

public static Task<int> CountAsync<TSource>(
	this IQueryable<TSource> source,
	CancellationToken cancellationToken
)

Parameters

source
Type: System.Linq.IQueryable<TSource>

An IQueryable<T> that contains the elements to be counted.

cancellationToken
Type: System.Threading.CancellationToken

A CancellationToken to observe while waiting for the task to complete.

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.

Type Parameters

TSource

The type of the elements of source.

Exception Condition
ArgumentNullException

source is null .

InvalidOperationException

source does not implement IDbAsyncQueryProvider .

OverflowException

The number of elements in source is larger than MaxValue.

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.


QueryableExtensions.CountAsync<TSource> Method (IQueryable<TSource>, Expression<Func<TSource, Boolean>>)

Asynchronously returns the number of elements in a sequence that satisfy a condition.

[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static Task<int> CountAsync<TSource>(
	this IQueryable<TSource> source,
	Expression<Func<TSource, bool>> predicate
)

Parameters

source
Type: System.Linq.IQueryable<TSource>

An IQueryable<T> that contains the elements to be counted.

predicate
Type: System.Linq.Expressions.Expression<Func<TSource, Boolean>>

A function to test each element for a condition.

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 sequence that satisfy the condition in the predicate function.

Type Parameters

TSource

The type of the elements of source.

Exception Condition
ArgumentNullException

source or predicate is null .

InvalidOperationException

source does not implement IDbAsyncQueryProvider .

OverflowException

The number of elements in source that satisfy the condition in the predicate function is larger than MaxValue.

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.


QueryableExtensions.CountAsync<TSource> Method (IQueryable<TSource>, Expression<Func<TSource, Boolean>>, CancellationToken)

Asynchronously returns the number of elements in a sequence that satisfy a condition.

[SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static Task<int> CountAsync<TSource>(
	this IQueryable<TSource> source,
	Expression<Func<TSource, bool>> predicate,
	CancellationToken cancellationToken
)

Parameters

source
Type: System.Linq.IQueryable<TSource>

An IQueryable<T> that contains the elements to be counted.

predicate
Type: System.Linq.Expressions.Expression<Func<TSource, Boolean>>

A function to test each element for a condition.

cancellationToken
Type: System.Threading.CancellationToken

A CancellationToken to observe while waiting for the task to complete.

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 sequence that satisfy the condition in the predicate function.

Type Parameters

TSource

The type of the elements of source.

Exception Condition
ArgumentNullException

source or predicate is null .

InvalidOperationException

source does not implement IDbAsyncQueryProvider.

OverflowException

The number of elements in source that satisfy the condition in the predicate function is larger than MaxValue .

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.