1

我有以下内容:

namespace BilBasen.Data.Migrations
{

    public class TestMigration : DbMigration
    {
        public override void Up()
        {

            CreateTable("TestMigrationTable", t => new { Id = t.Int(identity: true, nullable: false), Name = t.String(nullable: true) });
        }

        public override void Down()
        {
            DropTable("TestMigrationTable");
        }
    }

    public class MigrateExecuter
    {
        public void UpdateToLatest()
        {
            var conf = new DbMigrationsConfiguration<LocalInstans2Context>();
            conf.AutomaticMigrationsEnabled = false;
            conf.MigrationsNamespace = "BilBasen.Data.Migrations";
            conf.MigrationsAssembly = typeof(LocalInstans2Context).Assembly;
            var migrator = new DbMigrator(conf);


            migrator.Update();

        }
    }

    public class LocalInstans2Context : DbContext
    {

    }
}

迁移器未检测到迁移..

有什么建议么?

4

1 回答 1

1

安德斯,

您缺少 IMigrationMetadata。尝试:

public class TestMigration : DbMigration, IMigrationMetadata
{
    string IMigrationMetadata.Id
    {
        get { return "TestMigration "; }
    }

    string IMigrationMetadata.Source
    {
        get { return null; }
    }

    string IMigrationMetadata.Target
    {
        get { return "1"; }
    }


    public override void Up()
    {

        CreateTable("TestMigrationTable", t => new { Id = t.Int(identity: true, nullable: false), Name = t.String(nullable: true) });
    }

    public override void Down()
    {
        DropTable("TestMigrationTable");
    }
}
于 2012-09-21T21:48:02.367 回答