Delen via


EntityFrameworkQueryableExtensions.ForEachAsync<T> Method

Definition

Asynchronously enumerates the query results and performs the specified action on each element.

public static System.Threading.Tasks.Task ForEachAsync<T> (this System.Linq.IQueryable<T> source, Action<T> action, System.Threading.CancellationToken cancellationToken = default);
static member ForEachAsync : System.Linq.IQueryable<'T> * Action<'T> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
<Extension()>
Public Function ForEachAsync(Of T) (source As IQueryable(Of T), action As Action(Of T), Optional cancellationToken As CancellationToken = Nothing) As Task

Type Parameters

T

The type of the elements of source.

Parameters

source
IQueryable<T>

An IQueryable<T> to enumerate.

action
Action<T>

The action to perform on each element.

cancellationToken
CancellationToken

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

Returns

A task that represents the asynchronous operation.

Exceptions

source or action is null.

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 Avoiding DbContext threading issues for more information and examples.

See Querying data with EF Core for more information and examples.

Applies to