1
I have two context
in my project.
I followed as the basis of this Article
where it shows how to have 2 context
in the same project.
Each context
is for separate seats, so are 2 ConnectionString
However when using the command update-database
nothing happens, the syntax used is the same mentioned in the article:
Update-Database -configuration NameSpace.Configuration -Force -Verbose
In the file of Configuration
in both migrations
contains this configuration:
AutomaticMigrationsEnabled = true;
MigrationsDirectory = @"AppMigrations";
I added one more property to my class
, however it does not generate the column in the database.
I’m using Code First
[Edit] The code of each context is:
Context 1
public class MyDbContext : IdentityDbContext<Usuario, Role, int, UsuarioLogin, UsuarioRole, UsuarioClaim>
{
public MyDbContext()
: base("MyConnection")
{
Database.SetInitializer<MyDbContext>(new AppDbInitializer());
}
#region DbSets
public DbSet<Empresa> Empresas { get; set; }
#endregion
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Properties<DateTime>()
.Configure(x => x.HasColumnType("datetime2"));
}
public static MyDbContext Create()
{
return new MyDbContext();
}
}
My Context 2:
public class GlobalDbContext : DbContext
{
public GlobalDbContext()
: base("GlobalConnection")
{
Database.CreateIfNotExists();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<GlobalDbContext>(null);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Properties<DateTime>()
.Configure(x => x.HasColumnType("datetime2"));
base.OnModelCreating(modelBuilder);
}
public DbSet<CBO> CBOs { get; set; }
}
Reason to use 2 context:
A database (represented by context 1) is for each client The global context, are tables that will be used in all customers, so a global database with simple information not to repeat in all banks
Managed to solve?
– Renan
@Renan I did different, I did not use another db...because it would be more a db to give maintenance, as the data would not be shared with other applications, I put everything in the same db
– Rod