Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core and SqlAzureExecutionStrategy

I've tried to have a search for anything related to a SqlAzureExecutionStrategy for EF core and came up empty handed.

Does anyone have any information around the need for setting an execution strategy when using EF Core and SQL Azure?

like image 458
sf. Avatar asked Dec 06 '16 00:12

sf.


People also ask

What is SqlAzureExecutionStrategy?

The SqlAzureExecutionStrategy will retry instantly the first time a transient failure occurs, but will delay longer between each retry until either the max retry limit is exceeded or the total time hits the max delay.

What is EnableRetryOnFailure?

EnableRetryOnFailure() Configures the context to use the default retrying IExecutionStrategy. 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.

What is the difference between EF and EF core?

This is a high-level comparison and doesn't list every feature or explain differences between the same feature in different EF versions. The EF Core column indicates the product version in which the feature first appeared.

Is EF core faster than ef6?

EF Core 6.0 itself is 31% faster executing queries.


1 Answers

In EF Core it's called SqlServerRetryingExecutionStrategy as it is also useful for on-premise SQL Server if you are using memory-optimized tables for example.

It can be enabled in this way:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder
        .UseSqlServer(
            "<connection string>",
            options => options.EnableRetryOnFailure());
}

See Connection Resiliency for more info.

like image 188
Andriy Svyryd Avatar answered Sep 19 '22 15:09

Andriy Svyryd