检查 DBContext 是否有变化,并在 pot 上生成更新脚本,而不是使用 Package Manager Console

Check if there are changes in DBContext and Generate update script on the pot instead of using Package Manager Console

我想检查一下 DbContext 是否有任何变化并直接生成更新脚本而不是使用包管理器控制台(update-database -script -force -verbose -startupproject myproject)。

任何解决方案将不胜感激。

您可以在 DbMigratorMigratorScriptingDecorator 的帮助下将其归档:

var configuration = new Configuration();
var migrator = new DbMigrator(configuration);
//if you want to update database to latest migration
migrator.Update();

//if you want to get above update script without applying it to database
var scriptor = new MigratorScriptingDecorator(migrator);
var script = scriptor.ScriptUpdate(sourceMigration: null, targetMigration: null);