Class RelationalExecutionStrategyExtensions
- Namespace
- Microsoft.EntityFrameworkCore.Storage
- Assembly
- Microsoft.EntityFrameworkCore.Relational.dll
Extension methods for Microsoft.EntityFrameworkCore.Storage.IExecutionStrategy that can only be used with a relational database provider.
public static class RelationalExecutionStrategyExtensions
- Inheritance
-
RelationalExecutionStrategyExtensions
- Inherited Members
Remarks
See Connection resiliency and database retries for more information and examples.
Methods
ExecuteInTransaction(IExecutionStrategy, Action, Func<bool>, IsolationLevel)
Executes the specified operation in a transaction. Allows to check whether the transaction has been rolled back if an error occurs during commit.
public static void ExecuteInTransaction(this IExecutionStrategy strategy, Action operation, Func<bool> verifySucceeded, IsolationLevel isolationLevel)
Parameters
strategyIExecutionStrategyThe strategy that will be used for the execution.
operationActionA delegate representing an executable operation.
verifySucceededFunc<bool>A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.
isolationLevelIsolationLevelThe isolation level to use for the transaction.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
ExecuteInTransactionAsync(IExecutionStrategy, Func<CancellationToken, Task>, Func<CancellationToken, Task<bool>>, IsolationLevel, 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 Task ExecuteInTransactionAsync(this IExecutionStrategy strategy, Func<CancellationToken, Task> operation, Func<CancellationToken, Task<bool>> verifySucceeded, IsolationLevel isolationLevel, CancellationToken cancellationToken = default)
Parameters
strategyIExecutionStrategyThe strategy that will be used for the execution.
operationFunc<CancellationToken, Task>A function that returns a started task.
verifySucceededFunc<CancellationToken, Task<bool>>A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.
isolationLevelIsolationLevelThe isolation level to use for the transaction.
cancellationTokenCancellationTokenA cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.
Returns
- Task
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.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
- OperationCanceledException
If the CancellationToken is canceled.
ExecuteInTransactionAsync(IExecutionStrategy, Func<Task>, Func<Task<bool>>, IsolationLevel)
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 Task ExecuteInTransactionAsync(this IExecutionStrategy strategy, Func<Task> operation, Func<Task<bool>> verifySucceeded, IsolationLevel isolationLevel)
Parameters
strategyIExecutionStrategyThe strategy that will be used for the execution.
operationFunc<Task>A function that returns a started task.
verifySucceededFunc<Task<bool>>A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.
isolationLevelIsolationLevelThe isolation level to use for the transaction.
Returns
- Task
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.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
ExecuteInTransactionAsync<TResult>(IExecutionStrategy, Func<CancellationToken, Task<TResult>>, Func<CancellationToken, Task<bool>>, IsolationLevel, 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 Task<TResult> ExecuteInTransactionAsync<TResult>(this IExecutionStrategy strategy, Func<CancellationToken, Task<TResult>> operation, Func<CancellationToken, Task<bool>> verifySucceeded, IsolationLevel isolationLevel, CancellationToken cancellationToken = default)
Parameters
strategyIExecutionStrategyThe strategy that will be used for the execution.
operationFunc<CancellationToken, Task<TResult>>A function that returns a started task of type
TResult.verifySucceededFunc<CancellationToken, Task<bool>>A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.
isolationLevelIsolationLevelThe isolation level to use for the transaction.
cancellationTokenCancellationTokenA 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.
Type Parameters
TResultThe result type of the Task<TResult> returned by
operation.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
- OperationCanceledException
If the CancellationToken is canceled.
ExecuteInTransactionAsync<TState>(IExecutionStrategy, TState, Func<TState, CancellationToken, Task>, Func<TState, CancellationToken, Task<bool>>, IsolationLevel, 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 Task ExecuteInTransactionAsync<TState>(this IExecutionStrategy strategy, TState state, Func<TState, CancellationToken, Task> operation, Func<TState, CancellationToken, Task<bool>> verifySucceeded, IsolationLevel isolationLevel, CancellationToken cancellationToken = default)
Parameters
strategyIExecutionStrategyThe strategy that will be used for the execution.
stateTStateThe state that will be passed to the operation.
operationFunc<TState, CancellationToken, Task>A function that returns a started task.
verifySucceededFunc<TState, CancellationToken, Task<bool>>A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.
isolationLevelIsolationLevelThe isolation level to use for the transaction.
cancellationTokenCancellationTokenA cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.
Returns
- Task
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.
Type Parameters
TStateThe type of the state.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
- OperationCanceledException
If the CancellationToken is canceled.
ExecuteInTransactionAsync<TState, TResult>(IExecutionStrategy, TState, Func<TState, CancellationToken, Task<TResult>>, Func<TState, CancellationToken, Task<bool>>, IsolationLevel, CancellationToken)
Executes the specified asynchronous operation and returns the result. Allows to check whether the transaction has been rolled back if an error occurs during commit.
public static Task<TResult> ExecuteInTransactionAsync<TState, TResult>(this IExecutionStrategy strategy, TState state, Func<TState, CancellationToken, Task<TResult>> operation, Func<TState, CancellationToken, Task<bool>> verifySucceeded, IsolationLevel isolationLevel, CancellationToken cancellationToken = default)
Parameters
strategyIExecutionStrategyThe strategy that will be used for the execution.
stateTStateThe state that will be passed to the operation.
operationFunc<TState, CancellationToken, Task<TResult>>A function that returns a started task of type
TResult.verifySucceededFunc<TState, CancellationToken, Task<bool>>A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.
isolationLevelIsolationLevelThe isolation level to use for the transaction.
cancellationTokenCancellationTokenA 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.
Type Parameters
TStateThe type of the state.
TResultThe result type of the Task<TResult> returned by
operation.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
- OperationCanceledException
If the CancellationToken is canceled.
ExecuteInTransaction<TResult>(IExecutionStrategy, Func<TResult>, Func<bool>, IsolationLevel)
Executes the specified 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 TResult ExecuteInTransaction<TResult>(this IExecutionStrategy strategy, Func<TResult> operation, Func<bool> verifySucceeded, IsolationLevel isolationLevel)
Parameters
strategyIExecutionStrategyThe strategy that will be used for the execution.
operationFunc<TResult>A delegate representing an executable operation that returns the result of type
TResult.verifySucceededFunc<bool>A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.
isolationLevelIsolationLevelThe isolation level to use for the transaction.
Returns
- TResult
The result from the operation.
Type Parameters
TResultThe return type of
operation.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
ExecuteInTransaction<TState>(IExecutionStrategy, TState, Action<TState>, Func<TState, bool>, IsolationLevel)
Executes the specified operation in a transaction. Allows to check whether the transaction has been rolled back if an error occurs during commit.
public static void ExecuteInTransaction<TState>(this IExecutionStrategy strategy, TState state, Action<TState> operation, Func<TState, bool> verifySucceeded, IsolationLevel isolationLevel)
Parameters
strategyIExecutionStrategyThe strategy that will be used for the execution.
stateTStateThe state that will be passed to the operation.
operationAction<TState>A delegate representing an executable operation.
verifySucceededFunc<TState, bool>A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.
isolationLevelIsolationLevelThe isolation level to use for the transaction.
Type Parameters
TStateThe type of the state.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
ExecuteInTransaction<TState, TResult>(IExecutionStrategy, TState, Func<TState, TResult>, Func<TState, bool>, IsolationLevel)
Executes the specified 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 TResult ExecuteInTransaction<TState, TResult>(this IExecutionStrategy strategy, TState state, Func<TState, TResult> operation, Func<TState, bool> verifySucceeded, IsolationLevel isolationLevel)
Parameters
strategyIExecutionStrategyThe strategy that will be used for the execution.
stateTStateThe state that will be passed to the operation.
operationFunc<TState, TResult>A delegate representing an executable operation that returns the result of type
TResult.verifySucceededFunc<TState, bool>A delegate that tests whether the operation succeeded even though an exception was thrown when the transaction was being committed.
isolationLevelIsolationLevelThe isolation level to use for the transaction.
Returns
- TResult
The result from the operation.
Type Parameters
TStateThe type of the state.
TResultThe return type of
operation.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException
The operation has not succeeded after the configured number of retries.