public static void ConfigureSqlGeneratorForAllProviders( this DbMigrationsConfiguration migrationConfiguration) { var providers = migrationConfiguration.GetAvailableProviders(); foreach (var providerName in providers) { var currentSqlGenerator = migrationConfiguration.GetSqlGenerator(providerName); var newSqlGenerator = new MigrationSqlGeneratorWithDiscriminatorIndexSupport(currentSqlGenerator); migrationConfiguration.SetSqlGenerator(providerName, newSqlGenerator); } }
public static void ConfigureSqlGeneratorForAllProviders( this DbMigrationsConfiguration migrationConfiguration) { // Get Providers as copied list, the iteration edits the underlying enumerable var providers = migrationConfiguration.GetAvailableProviders().ToList(); foreach (var providerName in providers) { var currentSqlGenerator = migrationConfiguration.GetSqlGenerator(providerName); var newSqlGenerator = new MigrationSqlGeneratorWithDiscriminatorIndexSupport(currentSqlGenerator); migrationConfiguration.SetSqlGenerator(providerName, newSqlGenerator); } }
public static void Create(string connectionString, string schemaName) { var tenantDataMigrationsConfiguration = new DbMigrationsConfiguration <DataContext>(); tenantDataMigrationsConfiguration.AutomaticMigrationsEnabled = true; tenantDataMigrationsConfiguration.SetSqlGenerator("System.Data.SqlClient", new SqlServerSchemaAwareMigrationSqlGenerator(schemaName)); tenantDataMigrationsConfiguration.SetHistoryContextFactory("System.Data.SqlClient", (existingConnection, defaultSchema) => new HistoryContext(existingConnection, schemaName)); tenantDataMigrationsConfiguration.TargetDatabase = new System.Data.Entity.Infrastructure.DbConnectionInfo(connectionString, "System.Data.SqlClient"); tenantDataMigrationsConfiguration.MigrationsAssembly = typeof(DataContext).Assembly; tenantDataMigrationsConfiguration.MigrationsNamespace = "DataContext.Migrations.TestSchema"; DbMigrator tenantDataCtxMigrator = new DbMigrator(tenantDataMigrationsConfiguration); tenantDataCtxMigrator.Update(); }
public Boolean crearTenant() { var tenantDataMigrationsConfiguration = new DbMigrationsConfiguration <Kiosco>(); tenantDataMigrationsConfiguration.AutomaticMigrationsEnabled = false; tenantDataMigrationsConfiguration.SetSqlGenerator("System.Data.SqlClient", new SqlServerSchemaAwareMigrationSqlGenerator("nuevoSchemas")); tenantDataMigrationsConfiguration.SetHistoryContextFactory("System.Data.SqlClient", (existingConnection, defaultSchema) => new HistoryContext(existingConnection, "nuevoSchemas")); tenantDataMigrationsConfiguration.TargetDatabase = new System.Data.Entity.Infrastructure.DbConnectionInfo("data source=LAPTOP-ND2LJQD5;initial catalog=PruebaMultiTenantDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework", "System.Data.SqlClient"); tenantDataMigrationsConfiguration.MigrationsAssembly = typeof(Kiosco).Assembly; tenantDataMigrationsConfiguration.MigrationsNamespace = "AccesoADatos.Migrations.TenantData"; DbMigrator tenantDataCtxMigrator = new DbMigrator(tenantDataMigrationsConfiguration); tenantDataCtxMigrator.Update(); return(true); }
/// <summary> /// 配置使用Mysql注释。在Migration类(DbMigrationsConfiguration<DB>)的构造函数中使用。 /// </summary> /// <param name="c"></param> public static void UseMysqlComment(this DbMigrationsConfiguration c) { c.CodeGenerator = new ZMySqlMigrationCodeGenerator(); c.SetSqlGenerator("MySql.Data.MySqlClient", new ZMySqlMigrationSqlGenerator()); }