Reputation: 135
now if you have only one context for database , like applicationDbContext you are only have to run code in package nug >
PM>Enable-Migrations -ContextTypeName ApplicationDbContext -EnableAutomaticMigrations
I have one onthor dbcontext named MyDbContext in models, this for my own created models connection and ApplicationDbContext is only for user maintenance, because I have applied role not delete on MyDbContext for models relation which if I apply not delete in ApplicationDbContext it will distry the user and role identities so I applied in separate DbContext
in DbContext for not delete on relation is :
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
}
now how I am able to enable auto migration in both context in same project or just not delete for some moduls in applicationDbContext
thanks in advance
Upvotes: 1
Views: 157
Reputation: 1
public DataContext()
: base(nameOrConnectionString)
{
Database.SetInitializer<DataContext>(null);
}
When the database changes, change class as well
It will solve this problem
Upvotes: 0