Entity Framework Code First Migrations: get sql scripts programmatically
.net, c#, code-first, entity-framework
Solution
var configuration = new Configuration();
var migrator = new DbMigrator(configuration);
var scriptor = new MigratorScriptingDecorator(migrator);
var script = scriptor.ScriptUpdate(sourceMigration: null, targetMigration: null);
Console.WriteLine(script);
migrator.Update();
var pending = migrator.GetPendingMigrations();
more info: http://weblogs.asp.net/fredriknormen/archive/2012/02/15/using-entity-framework-4-3-database-migration-for-any-project.aspx
basically you need
DbMigrator db = new DbMigrator(HERE CONNECTION STRING);
db.Update(HERE TARGET VERSION);
Problem
I am implementing Entity Framework (v5) Code-Based Migrations for my project. The db admins from our clients are sometimes a little bit paranoid and want to execute the sql scripts by hand. Since we have got already many versions and we support SqlServer and Oracle parallel, we don't want to administer several update scripts from all possible versions x.x.x.x to y.y.y.y. Is it not possible to get programmatically the sql script in the same way as I call it in the Package Manager Console ``` Update-Database -Script ``` So the client would get via a simple console application depending his db system and current version the correct sql script as output.