From 16b62f1e192be9f0cb62a516b3aae55e0f58b5df Mon Sep 17 00:00:00 2001 From: Roman Marusyk Date: Fri, 7 Jan 2022 02:09:46 +0200 Subject: [PATCH] Add overload SqlServerDbContextOptionsBuilder.EnableRetryOnFailure without forcing maxRetryCount and maxRetryDelay --- .../SqlServerDbContextOptionsBuilder.cs | 20 +++++++++++++++++++ .../SqlServerRetryingExecutionStrategy.cs | 15 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs b/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs index 29d32e54f16..521960728a1 100644 --- a/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs +++ b/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs @@ -62,6 +62,26 @@ public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure() public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure(int maxRetryCount) => ExecutionStrategy(c => new SqlServerRetryingExecutionStrategy(c, maxRetryCount)); + /// + /// Configures the context to use the default retrying . + /// + /// + /// + /// This strategy is specifically tailored to SQL Server (including SQL Azure). It is pre-configured with + /// error numbers for transient errors that can be retried. + /// + /// + /// Default values of 6 for the maximum retry count and 30 seconds for the maximum default delay are used. + /// + /// + /// See Connection resiliency and database retries + /// for more information and examples. + /// + /// + /// Additional SQL error numbers that should be considered transient. + public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure(ICollection errorNumbersToAdd) + => ExecutionStrategy(c => new SqlServerRetryingExecutionStrategy(c, errorNumbersToAdd)); + /// /// Configures the context to use the default retrying . /// diff --git a/src/EFCore.SqlServer/SqlServerRetryingExecutionStrategy.cs b/src/EFCore.SqlServer/SqlServerRetryingExecutionStrategy.cs index 98c92750bdb..cca28b4a2eb 100644 --- a/src/EFCore.SqlServer/SqlServerRetryingExecutionStrategy.cs +++ b/src/EFCore.SqlServer/SqlServerRetryingExecutionStrategy.cs @@ -86,6 +86,21 @@ public SqlServerRetryingExecutionStrategy( { } + /// + /// Creates a new instance of . + /// + /// + /// Default values of 6 for the maximum retry count and 30 seconds for the maximum default delay are used. + /// + /// Parameter object containing service dependencies. + /// Additional SQL error numbers that should be considered transient. + public SqlServerRetryingExecutionStrategy( + ExecutionStrategyDependencies dependencies, + ICollection errorNumbersToAdd) + : this(dependencies, DefaultMaxRetryCount, DefaultMaxDelay, errorNumbersToAdd) + { + } + /// /// Creates a new instance of . ///