实体框架 - 每种类型的表不起作用

时间:2014-07-31 17:22:38

标签: c# .net entity-framework entity-framework-4

我正在使用Entity Framework 4.0,我有4个表:HistoryTedReceivedTedRepliedConfirmedCredit

在实体类中,History是abstract和TedReceived,TedReplied和ConfirmedCredit继承自History。

在DB中,最后三个表具有主+外键IdHistory。 (1-1与历史的关系)。

现在我映射了这样的类:

在上下文中:

modelBuilder.Configurations.Add(new HistoryMap());
modelBuilder.Configurations.Add(new TedReceivedMap());
modelBuilder.Configurations.Add(new TedRepliedMap());
modelBuilder.Configurations.Add(new ConfirmedCreditMap());

但这个例外是抛出:

  
    

(322,10):错误3032:从第310,322行开始映射片段时出现问题:EntityTypes TedReceivedEntity,TedRepliedEntity,ConfirmedCreditEntity被映射到表HistoryEntity中的相同行。映射条件可用于区分这些类型映射到的行。

  

任何人都可以帮助我?

更新

HistoryMap课程中:

public HistoryMap()
{
    HasKey(t => t.IdHistory);

    Property(t => t.IdHistory).HasColumnName("IdHistory");
    Property(t => t.IdSinister).HasColumnName("IdSinister");
    Property(t => t.IdUser).HasColumnName("IdUser");
    Property(t => t.IdSinisterStatus).HasColumnName("IdSinisterStatus");
    Property(t => t.UpdateDate).HasColumnName("UpdateDate");

    // Relationships
    this.HasRequired(t => t.Sinister)
        .WithMany(t => t.History)
        .HasForeignKey(d => d.IdSinister);
    this.HasRequired(t => t.SinisterStatus)
        .WithMany(t => t.History)
        .HasForeignKey(d => d.IdSinisterStatus);
    this.HasRequired(t => t.User)
        .WithMany(t => t.History)
        .HasForeignKey(d => d.IdUser);

    ToTable("History", "dbo");
}

TedReceivedMap课程中:

public TedReceived()
{
    HasKey(t => t.IdHistory);

    Property(t => t.IdHistory).HasColumnName("IdHistory");
    Property(t => t.Observation).HasColumnName("Observation");

    ToTable("TedReceived", "dbo");
}

实例化上下文类时发生异常:

var db = new Context();

0 个答案:

没有答案