Entity Framework, Automatic apply Migrations

后端 未结 4 544
后悔当初
后悔当初 2020-12-08 05:26

I am using Entity Framework Code First approach with AutomaticMigrationsEnabled = true:

Database.SetInitializer(new MigrateDatabaseToLatestVersi         


        
4条回答
  •  长情又很酷
    2020-12-08 06:12

    If you have change in your entities, you need first run add-migration to create the migration script.

    After that in your Global.asax

    you need to have some code like this

            var configuration = new MyProject.Configuration();
            var migrator = new System.Data.Entity.Migrations.DbMigrator(configuration);            
    
            migrator.Update();
    

    every time that you run your asp.net project it'll check if you have a new migration to run and run update-database automatically for you.

提交回复
热议问题