public SetSqlGenerator ( string providerInvariantName, System.Data.Entity.Migrations.Sql.MigrationSqlGenerator migrationSqlGenerator ) : void | ||
providerInvariantName | string | Name of the database provider to set the SQL generator for. |
migrationSqlGenerator | System.Data.Entity.Migrations.Sql.MigrationSqlGenerator | The SQL generator to be used. |
Результат | void |
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 void Can_add_and_get_sql_generator() { var migrationsConfiguration = new DbMigrationsConfiguration(); var migrationSqlGenerator = new SqlServerMigrationSqlGenerator(); migrationsConfiguration.SetSqlGenerator(DbProviders.Sql, migrationSqlGenerator); Assert.Same(migrationSqlGenerator, migrationsConfiguration.GetSqlGenerator(DbProviders.Sql)); }
public void Can_add_and_get_sql_generator() { var migrationsConfiguration = new DbMigrationsConfiguration(); var migrationSqlGenerator = new SqlServerMigrationSqlGenerator(); migrationsConfiguration.SetSqlGenerator(DbProviders.Sql, migrationSqlGenerator); Assert.Same(migrationSqlGenerator, migrationsConfiguration.GetSqlGenerator(DbProviders.Sql)); }
public void Can_use_custom_operations() { var configuration = new DbMigrationsConfiguration<EmptyModel> { MigrationsAssembly = typeof(CustomOperationMigration).Assembly(), MigrationsNamespace = typeof(CustomOperationMigration).Namespace }; configuration.SetSqlGenerator("System.Data.SqlClient", new CustomSqlGenerator()); var migrator = new DbMigrator(configuration); var scriptor = new MigratorScriptingDecorator(migrator); var sql = scriptor.ScriptUpdate(DbMigrator.InitialDatabase, null); Assert.Contains("-- This is a test.", sql); }
public void Can_use_custom_operations() { var configuration = new DbMigrationsConfiguration <EmptyModel> { MigrationsAssembly = typeof(CustomOperationMigration).Assembly, MigrationsNamespace = typeof(CustomOperationMigration).Namespace }; configuration.SetSqlGenerator("System.Data.SqlClient", new CustomSqlGenerator()); var migrator = new DbMigrator(configuration); var scriptor = new MigratorScriptingDecorator(migrator); var sql = scriptor.ScriptUpdate(DbMigrator.InitialDatabase, null); Assert.Contains("-- This is a test.", sql); }
private static void SetSqlGeneratorTest(bool setGenerator) { var generator = new Mock <MigrationSqlGenerator>().Object; var mockResolver = new Mock <IDbDependencyResolver>(); mockResolver.Setup(m => m.GetService(typeof(MigrationSqlGenerator), "Gu.Hu.Ha")).Returns(generator); var migrationsConfiguration = new DbMigrationsConfiguration(new Lazy <IDbDependencyResolver>(() => mockResolver.Object)); if (setGenerator) { generator = new Mock <MigrationSqlGenerator>().Object; migrationsConfiguration.SetSqlGenerator("Gu.Hu.Ha", generator); } Assert.Same(generator, migrationsConfiguration.GetSqlGenerator("Gu.Hu.Ha")); }
private static void SetSqlGeneratorTest(bool setGenerator) { var generator = new Mock<MigrationSqlGenerator>().Object; var mockResolver = new Mock<IDbDependencyResolver>(); mockResolver.Setup(m => m.GetService(typeof(MigrationSqlGenerator), "Gu.Hu.Ha")).Returns(generator); var mockConfiguration = new Mock<DbConfiguration>(); mockConfiguration.Setup(m => m.DependencyResolver).Returns(mockResolver.Object); var migrationsConfiguration = new DbMigrationsConfiguration(new Lazy<DbConfiguration>(() => mockConfiguration.Object)); if (setGenerator) { generator = new Mock<MigrationSqlGenerator>().Object; migrationsConfiguration.SetSqlGenerator("Gu.Hu.Ha", generator); } Assert.Same(generator, migrationsConfiguration.GetSqlGenerator("Gu.Hu.Ha")); }