Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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);
        }