简体   繁体   中英

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

I would like to check see whether is there any change in DbContext and generate update script right on the pot instead of using Package Manager Console( update-database -script -force -verbose -startupproject myproject ).

Any solution would be appreciate.

You can archive it with help of DbMigrator and MigratorScriptingDecorator :

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM