12

有没有办法从应用程序本身运行迁移?

谢谢!

4

2 回答 2

13

我实例化了一个 Migrator 类的实例,然后你可以调用成员方法,例如MigrateToLastVersion()MigrateTo(long versionnr)

Migrator.Migrator m = new Migrator.Migrator ("SqlServer", connectionString, migrationsAssembly)

m.MigrateToLastVersion();
于 2009-05-15T11:49:38.903 回答
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);
    }
于 2009-05-15T11:51:35.873 回答