DbMigrator - 详细代码优先迁移

ves*_*san 7 .net c# entity-framework ef-migrations

使用程序包管理器控制台时,可以运行以下命令:

PM> Update-Database -Verbose
Run Code Online (Sandbox Code Playgroud)

-Verbose交换机将所有尝试的SQL命令写入控制台窗口,这对于调试是非常有用的.

您可以使用DbMigrator该类在代码中执行相同的操作:

Configuration config = new Configuration();
//... (set up the config object)
DbMigrator migrator = new DbMigrator(config);
migrator.Update();
Run Code Online (Sandbox Code Playgroud)

-Verbose如果你使用这DbMigrator门课,有没有类似开关的东西?我查看了整个文档,但找不到任何东西.

Bjø*_*nap 9

看看这篇文章是否解决了你的问题:

http://whiteknight.github.io/2013/01/26/efcodeonlymigrations.html

简而言之:

MigratorScriptingDecorator scripter = new MigratorScriptingDecorator(migrator);
string script = scripter.ScriptUpdate(null, null);
Run Code Online (Sandbox Code Playgroud)