有没有办法从应用程序本身运行迁移?
谢谢!
我实例化了一个 Migrator 类的实例,然后你可以调用成员方法,例如MigrateToLastVersion()
或MigrateTo(long versionnr)
Migrator.Migrator m = new Migrator.Migrator ("SqlServer", connectionString, migrationsAssembly)
m.MigrateToLastVersion();
我不明白为什么不。
看看 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);
}