EF Code First DbMigration without nuget

前端 未结 6 915
长发绾君心
长发绾君心 2020-12-16 00:27

How to migrate DB without nuget? It is not possible to use Visual Studio with nuget in production environment. Currently, many examples only teach us to use Visual Studio wi

6条回答
  •  余生分开走
    2020-12-16 01:00

    The easiest way is:

    Database.SetInitializer(
        new MigrateDatabaseToLatestVersion());
    

    This will run the migrations when initializing the DbContext.

    You can also force the execution manually:

    var migrator = new DbMigrator(new MyMigrationsConfiguration());
    migrator.Update();
    

    (I believe you also have to set TargetDatabase on the configuration, but you can try)

提交回复
热议问题