我正在使用Entity Framework 4.0,我有4个表:History
,TedReceived
,TedReplied
和ConfirmedCredit
。
在实体类中,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();