0 votes
1 view
in Azure by (32.3k points)

I saw a post today about implementing SqlAzureExecutionStrategy: 

http://romiller.com/tag/sqlazureexecutionstrategy/

However, all examples I can find of this use a Configuration that inherits from DbConfiguration. My project is using EF6 Code First Migrations, and the Configuration it created inherits from DbMigrationsConfiguration. This class doesn't contain a definition for SetExecutionStrategy, and I can find no examples that actually combine SqlAzureExecutionStrategy (or any SetExecutionStrategy) with DbMigrationsConfiguration.

Can this be done?

1 Answer

0 votes
by (16.8k points)

First, create a custom class which is able to inherit from DbConfiguration containing SetExecutionStrategy:

public class DataContextConfiguration : DbConfiguration

{

    public DataContextConfiguration()

    {

        SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());

    }

}

Then add this attribute to your DataContext, specifying that it is to use your custom class:

[DbConfigurationType(typeof(DataContextConfiguration))]

public class DataContext : DbContext, IDataContext

{

    ...

}

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...