ExecutionStrategyExtensions.ExecuteInTransactionAsync Method

Definition

Overloads

ExecuteInTransactionAsync(IExecutionStrategy, Func<Task>, Func<Task<Boolean>>)

Executes the specified asynchronous operation in a transaction. Allows to check whether the transaction has been rolled back if an error occurs during commit.

ExecuteInTransactionAsync(IExecutionStrategy, Func<CancellationToken,Task>, Func<CancellationToken,Task<Boolean>>, CancellationToken)

Executes the specified asynchronous operation in a transaction. Allows to check whether the transaction has been rolled back if an error occurs during commit.

ExecuteInTransactionAsync<TResult>(IExecutionStrategy, Func<CancellationToken, Task<TResult>>, Func<CancellationToken,Task<Boolean>>, CancellationToken)

Executes the specified asynchronous operation in a transaction and returns the result. Allows to check whether the transaction has been rolled back if an error occurs during commit.

ExecuteInTransactionAsync<TState,TResult>(IExecutionStrategy, Func<TState,CancellationToken,Task<TResult>>, Func<TState,CancellationToken, Task<Boolean>>, TState, DbContext, CancellationToken)

Executes the specified asynchronous operation and returns the result.

ExecuteInTransactionAsync<TState,TResult>(IExecutionStrategy, TState, Func<TState,CancellationToken,Task<TResult>>, Func<TState, CancellationToken,Task<Boolean>>, CancellationToken)

Executes the specified asynchronous operation in a transaction and returns the result. Allows to check whether the transaction has been rolled back if an error occurs during commit.

ExecuteInTransactionAsync<TState,TResult>(IExecutionStrategy, TState, Func<TState,CancellationToken,Task<TResult>>, Func<TState, CancellationToken,Task<Boolean>>, Func<DbContext,CancellationToken, Task<IDbContextTransaction>>, CancellationToken)

Executes the specified asynchronous operation in a transaction and returns the result. Allows to check whether the transaction has been rolled back if an error occurs during commit.

ExecuteInTransactionAsync<TState>(IExecutionStrategy, TState, Func<TState,CancellationToken,Task>, Func<TState,CancellationToken, Task<Boolean>>, CancellationToken)

Executes the specified asynchronous operation in a transaction. Allows to check whether the transaction has been rolled back if an error occurs during commit.

ExecuteInTransactionAsync(IExecutionStrategy, Func<Task>, Func<Task<Boolean>>)

Executes the specified asynchronous operation in a transaction. Allows to check whether the transaction has been rolled back if an error occurs during commit.

public static System.Threading.Tasks.Task ExecuteInTransactionAsync (this Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy strategy, Func<System.Threading.Tasks.Task> operation, Func<System.Threading.Tasks.Task<bool>> verifySucceeded);
static member ExecuteInTransactionAsync : Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy * Func<System.Threading.Tasks.Task> * Func<System.Threading.Tasks.Task<bool>> -> System.Threading.Tasks.Task
<Extension()>
Public Function ExecuteInTransactionAsync (strategy As IExecutionStrategy, operation As Func(Of Task), verifySucceeded As Func(Of Task(Of Boolean))) As Task

Parameters

strategy
IExecutionStrategy

The strategy that will be used for the execution.

operation
Func<Task>

A function that returns a started task.

verifySucceeded
Func<Task<Boolean>>

A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.

Returns

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

Exceptions

The operation has not succeeded after the configured number of retries.

Remarks

See Connection resiliency and database retries for more information and examples.

Applies to

ExecuteInTransactionAsync(IExecutionStrategy, Func<CancellationToken,Task>, Func<CancellationToken,Task<Boolean>>, CancellationToken)

Executes the specified asynchronous operation in a transaction. Allows to check whether the transaction has been rolled back if an error occurs during commit.

public static System.Threading.Tasks.Task ExecuteInTransactionAsync (this Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy strategy, Func<System.Threading.CancellationToken,System.Threading.Tasks.Task> operation, Func<System.Threading.CancellationToken,System.Threading.Tasks.Task<bool>> verifySucceeded, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteInTransactionAsync : Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy * Func<System.Threading.CancellationToken, System.Threading.Tasks.Task> * Func<System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
<Extension()>
Public Function ExecuteInTransactionAsync (strategy As IExecutionStrategy, operation As Func(Of CancellationToken, Task), verifySucceeded As Func(Of CancellationToken, Task(Of Boolean)), Optional cancellationToken As CancellationToken = Nothing) As Task

Parameters

strategy
IExecutionStrategy

The strategy that will be used for the execution.

operation
Func<CancellationToken,Task>

A function that returns a started task.

verifySucceeded
Func<CancellationToken,Task<Boolean>>

A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.

cancellationToken
CancellationToken

A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

Returns

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

Exceptions

The operation has not succeeded after the configured number of retries.

Remarks

See Connection resiliency and database retries for more information and examples.

Applies to

ExecuteInTransactionAsync<TResult>(IExecutionStrategy, Func<CancellationToken, Task<TResult>>, Func<CancellationToken,Task<Boolean>>, CancellationToken)

Executes the specified asynchronous operation in a transaction and returns the result. Allows to check whether the transaction has been rolled back if an error occurs during commit.

public static System.Threading.Tasks.Task<TResult> ExecuteInTransactionAsync<TResult> (this Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy strategy, Func<System.Threading.CancellationToken,System.Threading.Tasks.Task<TResult>> operation, Func<System.Threading.CancellationToken,System.Threading.Tasks.Task<bool>> verifySucceeded, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteInTransactionAsync : Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy * Func<System.Threading.CancellationToken, System.Threading.Tasks.Task<'Result>> * Func<System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
<Extension()>
Public Function ExecuteInTransactionAsync(Of TResult) (strategy As IExecutionStrategy, operation As Func(Of CancellationToken, Task(Of TResult)), verifySucceeded As Func(Of CancellationToken, Task(Of Boolean)), Optional cancellationToken As CancellationToken = Nothing) As Task(Of TResult)

Type Parameters

TResult

The result type of the Task<TResult> returned by operation.

Parameters

strategy
IExecutionStrategy

The strategy that will be used for the execution.

operation
Func<CancellationToken,Task<TResult>>

A function that returns a started task of type TResult.

verifySucceeded
Func<CancellationToken,Task<Boolean>>

A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.

cancellationToken
CancellationToken

A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

Returns

Task<TResult>

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

Exceptions

The operation has not succeeded after the configured number of retries.

Remarks

See Connection resiliency and database retries for more information and examples.

Applies to

ExecuteInTransactionAsync<TState,TResult>(IExecutionStrategy, Func<TState,CancellationToken,Task<TResult>>, Func<TState,CancellationToken, Task<Boolean>>, TState, DbContext, CancellationToken)

Executes the specified asynchronous operation and returns the result.

public static System.Threading.Tasks.Task<TResult> ExecuteInTransactionAsync<TState,TResult> (this Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy strategy, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<TResult>> operation, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<bool>> verifySucceeded, TState state, Microsoft.EntityFrameworkCore.DbContext context, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteInTransactionAsync : Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<'Result>> * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>> * 'State * Microsoft.EntityFrameworkCore.DbContext * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
<Extension()>
Public Function ExecuteInTransactionAsync(Of TState, TResult) (strategy As IExecutionStrategy, operation As Func(Of TState, CancellationToken, Task(Of TResult)), verifySucceeded As Func(Of TState, CancellationToken, Task(Of Boolean)), state As TState, context As DbContext, Optional cancellationToken As CancellationToken = Nothing) As Task(Of TResult)

Type Parameters

TState

The type of the state.

TResult

The result type of the Task<TResult> returned by operation.

Parameters

strategy
IExecutionStrategy

The strategy that will be used for the execution.

operation
Func<TState,CancellationToken,Task<TResult>>

A function that returns a started task of type TResult.

verifySucceeded
Func<TState,CancellationToken,Task<Boolean>>

A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.

state
TState

The state that will be passed to the operation.

context
DbContext

The context that will be used to start the transaction.

cancellationToken
CancellationToken

A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

Returns

Task<TResult>

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

Exceptions

Thrown if the operation has not succeeded after the configured number of retries.

Applies to

ExecuteInTransactionAsync<TState,TResult>(IExecutionStrategy, TState, Func<TState,CancellationToken,Task<TResult>>, Func<TState, CancellationToken,Task<Boolean>>, CancellationToken)

Executes the specified asynchronous operation in a transaction and returns the result. Allows to check whether the transaction has been rolled back if an error occurs during commit.

public static System.Threading.Tasks.Task<TResult> ExecuteInTransactionAsync<TState,TResult> (this Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy strategy, TState state, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<TResult>> operation, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<bool>> verifySucceeded, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteInTransactionAsync : Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy * 'State * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<'Result>> * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
<Extension()>
Public Function ExecuteInTransactionAsync(Of TState, TResult) (strategy As IExecutionStrategy, state As TState, operation As Func(Of TState, CancellationToken, Task(Of TResult)), verifySucceeded As Func(Of TState, CancellationToken, Task(Of Boolean)), Optional cancellationToken As CancellationToken = Nothing) As Task(Of TResult)

Type Parameters

TState

The type of the state.

TResult

The result type of the Task<TResult> returned by operation.

Parameters

strategy
IExecutionStrategy

The strategy that will be used for the execution.

state
TState

The state that will be passed to the operation.

operation
Func<TState,CancellationToken,Task<TResult>>

A function that returns a started task of type TResult.

verifySucceeded
Func<TState,CancellationToken,Task<Boolean>>

A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.

cancellationToken
CancellationToken

A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

Returns

Task<TResult>

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

Exceptions

The operation has not succeeded after the configured number of retries.

Remarks

See Connection resiliency and database retries for more information and examples.

Applies to

ExecuteInTransactionAsync<TState,TResult>(IExecutionStrategy, TState, Func<TState,CancellationToken,Task<TResult>>, Func<TState, CancellationToken,Task<Boolean>>, Func<DbContext,CancellationToken, Task<IDbContextTransaction>>, CancellationToken)

Executes the specified asynchronous operation in a transaction and returns the result. Allows to check whether the transaction has been rolled back if an error occurs during commit.

public static System.Threading.Tasks.Task<TResult> ExecuteInTransactionAsync<TState,TResult> (Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy strategy, TState state, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<TResult>> operation, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<bool>> verifySucceeded, Func<Microsoft.EntityFrameworkCore.DbContext,System.Threading.CancellationToken,System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction>> beginTransaction, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteInTransactionAsync : Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy * 'State * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<'Result>> * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>> * Func<Microsoft.EntityFrameworkCore.DbContext, System.Threading.CancellationToken, System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Function ExecuteInTransactionAsync(Of TState, TResult) (strategy As IExecutionStrategy, state As TState, operation As Func(Of TState, CancellationToken, Task(Of TResult)), verifySucceeded As Func(Of TState, CancellationToken, Task(Of Boolean)), beginTransaction As Func(Of DbContext, CancellationToken, Task(Of IDbContextTransaction)), Optional cancellationToken As CancellationToken = Nothing) As Task(Of TResult)

Type Parameters

TState

The type of the state.

TResult

The result type of the Task<TResult> returned by operation.

Parameters

strategy
IExecutionStrategy

The strategy that will be used for the execution.

state
TState

The state that will be passed to the operation.

operation
Func<TState,CancellationToken,Task<TResult>>

A function that returns a started task of type TResult.

verifySucceeded
Func<TState,CancellationToken,Task<Boolean>>

A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.

beginTransaction
Func<DbContext,CancellationToken,Task<IDbContextTransaction>>

A delegate that begins a transaction using the given context.

cancellationToken
CancellationToken

A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

Returns

Task<TResult>

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

Exceptions

The operation has not succeeded after the configured number of retries.

Remarks

See Connection resiliency and database retries for more information and examples.

Applies to

ExecuteInTransactionAsync<TState>(IExecutionStrategy, TState, Func<TState,CancellationToken,Task>, Func<TState,CancellationToken, Task<Boolean>>, CancellationToken)

Executes the specified asynchronous operation in a transaction. Allows to check whether the transaction has been rolled back if an error occurs during commit.

public static System.Threading.Tasks.Task ExecuteInTransactionAsync<TState> (this Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy strategy, TState state, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task> operation, Func<TState,System.Threading.CancellationToken,System.Threading.Tasks.Task<bool>> verifySucceeded, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteInTransactionAsync : Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy * 'State * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task> * Func<'State, System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
<Extension()>
Public Function ExecuteInTransactionAsync(Of TState) (strategy As IExecutionStrategy, state As TState, operation As Func(Of TState, CancellationToken, Task), verifySucceeded As Func(Of TState, CancellationToken, Task(Of Boolean)), Optional cancellationToken As CancellationToken = Nothing) As Task

Type Parameters

TState

The type of the state.

Parameters

strategy
IExecutionStrategy

The strategy that will be used for the execution.

state
TState

The state that will be passed to the operation.

operation
Func<TState,CancellationToken,Task>

A function that returns a started task.

verifySucceeded
Func<TState,CancellationToken,Task<Boolean>>

A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.

cancellationToken
CancellationToken

A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

Returns

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

Exceptions

The operation has not succeeded after the configured number of retries.

Remarks

See Connection resiliency and database retries for more information and examples.

Applies to