dbmigrator未检测到迁移

时间:2012-03-23 11:15:52

标签: c# entity-framework-4.3 ef-migrations

我有以下内容:

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
    {

    }
}

迁移器未检测到迁移..

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

的Anders,

您缺少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");
    }
}