I have created an app using the lastest ASP.NET5 MVC 6 Entity Framework 7 and setup migrations using
dnx . ef migration add Initial
dnx . ef migration apply
This works but when I make a change to the model the database is not updated. I would like to have the database automatically update after a model change when I run the program.
My research only points me to old information that doesn't seem to be appropriate to Entity Framework 7.
My current code:
public ApplicationDbContext(): base()
{
if (!_created)
{
Database.AsRelational().ApplyMigrations();
_created = true;
}
}
Can someone point me in the right direction?
I believe it use to work something like this:
Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());
Database.EnsureDeleted(); if (Database.EnsureCreated()) { // Database.AsRelational().ApplyMigrations(); _created = true; }but that deletes my test data every time.