migratordotnet - 从应用程序内部运行迁移(无需或构建)

时间:2009-05-15 11:46:46

标签: c# .net .net-3.5 .net-2.0 migrator.net

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

谢谢!

2 个答案:

答案 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);
    }