public DbMigrationsConfiguration CreateMigrationsConfiguration <TContext>( bool automaticMigrationsEnabled = true, bool automaticDataLossEnabled = false, string targetDatabase = null, string contextKey = null, Func <DbConnection, string, HistoryContext> historyContextFactory = null, IEnumerable <Tuple <string, MigrationSqlGenerator> > sqlGenerators = null, params ScaffoldedMigration[] scaffoldedMigrations) where TContext : DbContext { var migrationsConfiguration = new DbMigrationsConfiguration { AutomaticMigrationsEnabled = automaticMigrationsEnabled, AutomaticMigrationDataLossAllowed = automaticDataLossEnabled, ContextType = typeof(TContext), MigrationsAssembly = SystemComponentModelDataAnnotationsAssembly, MigrationsNamespace = typeof(TContext).Namespace }; if (historyContextFactory != null) { migrationsConfiguration.SetHistoryContextFactory(TestDatabase.ProviderName, historyContextFactory); } if (!string.IsNullOrWhiteSpace(contextKey)) { migrationsConfiguration.ContextKey = contextKey; } if (!string.IsNullOrWhiteSpace(targetDatabase)) { TestDatabase = DatabaseProviderFixture.InitializeTestDatabase(DatabaseProvider, targetDatabase); } if ((scaffoldedMigrations != null) && scaffoldedMigrations.Any()) { migrationsConfiguration.MigrationsAssembly = MigrationCompiler.Compile( migrationsConfiguration.MigrationsNamespace, scaffoldedMigrations); } migrationsConfiguration.TargetDatabase = new DbConnectionInfo(TestDatabase.ConnectionString, TestDatabase.ProviderName); migrationsConfiguration.CodeGenerator = CodeGenerator; if (sqlGenerators != null) { foreach (var sqlGenerator in sqlGenerators) { migrationsConfiguration.SetSqlGenerator(sqlGenerator.Item1, sqlGenerator.Item2); } } ModifyMigrationsConfiguration(migrationsConfiguration); return(migrationsConfiguration); }
public virtual void Init(DatabaseProvider provider, ProgrammingLanguage language) { try { _databaseProvider = provider; _programmingLanguage = language; TestDatabase = _databaseProviderFixture.TestDatabases[_databaseProvider]; CodeGenerator = _databaseProviderFixture.CodeGenerators[_programmingLanguage]; MigrationCompiler = _databaseProviderFixture.MigrationCompilers[_programmingLanguage]; } catch (Exception e) { Console.WriteLine(e); throw; } }