EF Code First DbMigrator takes a long time to instantiate

We start the migration from our database application on the fly. We also use migration in our unit / integration tests to create databases for using tests. A few months ago, we noticed that the execution time of our tests increased significantly, and we were able to narrow it down to the creation of the DbMigrator class. Even with a very simple Configuration class, it takes ~ 10 seconds to create a DbMigrator .

For example, the configuration class used here is taken from the sample application "Elastic DB Tools-Entity Framework".

 internal sealed class Configuration : DbMigrationsConfiguration<ElasticScaleContext<int>> { public Configuration() { this.AutomaticMigrationsEnabled = false; this.ContextKey = "CodeFirstNewDatabaseSample.BloggingContext"; } } 

Here is the code used to create and run the migration.

 var configurator = new Configuration(); configurator.TargetDatabase = new DbConnectionInfo(connStrBldr.ConnectionString, "System.Data.SqlClient"); var migrator = new DbMigrator(configurator); migrator.Update(); 

And here is the trace information from VS2015.

enter image description here

  • Time to create an instance of Configuration
  • Time to set the TargetDatabase property
  • Time to create an instance of DbMigrator

We are using Entity Framework 6.1.3. Has anyone else experienced this?

+6
source share

All Articles