我正在使用Entity Framework 5 code first
. 在我的数据库中,我有 2 个表,AvailPayPeriods
并且AvailPayPeriodsWeekly
. 它们看起来都一样:
Period datetime not null
因为这 2 个表本质上是相同的,所以我决定创建以下类来表示 2 个中的 1 个:
public class PayPeriod : IEntity
{
public int Id { get; set; }
public DateTime Period { get; set; }
}
我正在努力配置 2。我的数据库上下文类中有以下内容:
public DbSet<PayPeriod> WeeklyPayPeriods { get; set; }
public DbSet<PayPeriod> MonthlyPayPeriods { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new WeeklyPayPeriodConfiguration());
// Haven't yet created the configuration file for monthly pay periods
}
我的WeeklyPayPeriodConfiguration
班级:
class WeeklyPayPeriodConfiguration : EntityTypeConfiguration<PayPeriod>
{
internal WeeklyPayPeriodConfiguration()
{
this.ToTable("AvailPayPeriodsWeekly");
}
}
当我调用我的存储库以取回每周支付期时,我收到以下错误:
Multiple object sets per type are not supported. The object sets 'WeeklyPayPeriods' and 'MonthlyPayPeriods' can both contain instances of type 'ePaySlips.DomainModel.Entities.PayPeriod'.
如何将 2 映射到各自的表?
我是否应该创建单独的名为WeeklyPayPeriod
and的类MonthlyPayPeriod
?