Ef表分裂

时间:2014-02-18 19:11:33

标签: c# entity-framework

有人可以解释原因吗

class TestA
{
    public int TestAId { get; set; }
    public string A { get; set; }
    public TestB TestB { get; set; }
}

class TestB
{
    public int TestBId { get; set; }
    public string B { get; set; }
    public TestA TestA { get; set; }
}

class TestContext : DbContext
{
    public DbSet<TestA> TestAs { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<TestB>().Property(t => t.TestBId).HasColumnName("TestAId");
        modelBuilder.Entity<TestB>().HasRequired(t => t.TestA).WithRequiredDependent(t => t.TestB);
        modelBuilder.Entity<TestB>().ToTable("Test");
        modelBuilder.Entity<TestA>().ToTable("Test");
    }
}

效果很好,但如果我尝试制作TestB校长

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<TestB>().Property(t => t.TestBId).HasColumnName("TestAId");
    modelBuilder.Entity<TestB>().HasRequired(t => t.TestA).WithRequiredPrincipal(t => t.TestB);
    modelBuilder.Entity<TestB>().ToTable("Test");
    modelBuilder.Entity<TestA>().ToTable("Test");
}

失败,但例外情况是:

  

为表'Test'指定了多个标识列。只有一个   允许每个表的标识列。它看起来像个bug。

0 个答案:

没有答案