Interface IExecutionStrategy
- Namespace
- Microsoft.EntityFrameworkCore.Storage
- Assembly
- Microsoft.EntityFrameworkCore.dll
A strategy that is used to execute a command or query against the database, possibly with logic to retry when a failure occurs.
public interface IExecutionStrategy
- Extension Methods
Remarks
The service lifetime is Scoped. This means that each DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.
See Connection resiliency and database retries for more information and examples.
Properties
RetriesOnFailure
Indicates whether this IExecutionStrategy might retry the execution after a failure.
bool RetriesOnFailure { get; }
Property Value
Remarks
See Connection resiliency and database retries for more information and examples.
Methods
ExecuteAsync<TState, TResult>(TState, Func<DbContext, TState, CancellationToken, Task<TResult>>, Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>>?, CancellationToken)
Executes the specified asynchronous operation and returns the result.
Task<TResult> ExecuteAsync<TState, TResult>(TState state, Func<DbContext, TState, CancellationToken, Task<TResult>> operation, Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>>? verifySucceeded, CancellationToken cancellationToken = default)
Parameters
state
TStateThe state that will be passed to the operation.
operation
Func<DbContext, TState, CancellationToken, Task<TResult>>A function that returns a started task of type
TResult
.verifySucceeded
Func<DbContext, TState, CancellationToken, Task<ExecutionResult<TResult>>>A delegate that tests whether the operation succeeded even though an exception was thrown.
cancellationToken
CancellationTokenA 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
TState
The type of the state.
TResult
The result type of the Task<TResult> returned by
operation
.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- RetryLimitExceededException
The operation has not succeeded after the configured number of retries.
- OperationCanceledException
If the CancellationToken is canceled.
Execute<TState, TResult>(TState, Func<DbContext, TState, TResult>, Func<DbContext, TState, ExecutionResult<TResult>>?)
Executes the specified operation and returns the result.
TResult Execute<TState, TResult>(TState state, Func<DbContext, TState, TResult> operation, Func<DbContext, TState, ExecutionResult<TResult>>? verifySucceeded)
Parameters
state
TStateThe state that will be passed to the operation.
operation
Func<DbContext, TState, TResult>A delegate representing an executable operation that returns the result of type
TResult
.verifySucceeded
Func<DbContext, TState, ExecutionResult<TResult>>A delegate that tests whether the operation succeeded even though an exception was thrown.
Returns
- TResult
The result from the operation.
Type Parameters
TState
The type of the state.
TResult
The return type of
operation
.
Remarks
See Connection resiliency and database retries for more information and examples.
Exceptions
- RetryLimitExceededException
The operation has not succeeded after the configured number of retries.