有没有办法从应用程序本身运行迁移?
谢谢!
答案 0 :(得分:13)
我实例化Migrator类的实例,然后您可以调用MigrateToLastVersion()
或MigrateTo(long versionnr)
等成员方法
Migrator.Migrator m = new Migrator.Migrator ("SqlServer", connectionString, migrationsAssembly)
m.MigrateToLastVersion();
答案 1 :(得分:1)
我不明白为什么不。
查看nant任务http://code.google.com/p/migratordotnet/source/browse/trunk/src/Migrator.NAnt/MigrateTask.cs
相关位在这里:
private void Execute(Assembly asm)
{
Migrator mig = new Migrator(Provider, ConnectionString, asm, Trace, new TaskLogger(this));
mig.DryRun = DryRun;
if (ScriptChanges)
{
using (StreamWriter writer = new StreamWriter(ScriptFile))
{
mig.Logger = new SqlScriptFileLogger(mig.Logger, writer);
RunMigration(mig);
}
}
else
{
RunMigration(mig);
}
}
private void RunMigration(Migrator mig)
{
if (mig.DryRun)
mig.Logger.Log("********** Dry run! Not actually applying changes. **********");
if (_to == -1)
mig.MigrateToLastVersion();
else
mig.MigrateTo(_to);
}