我有两个实体,它们之间存在一对一的关系,其中目标实体的主键和外键相同。以下是两个实体及其流畅映射。
public class Register
{
public int Id { get; set; }
public string Number { get; set; }
// N.B: Here I can't have this virtual property for my project dependencies.
//public virtual CustomerDisplay CustomerDisplay { get; set; }
}
public class CustomerDisplay
{
public int RegisterId { get; set; }
public double ReceiptViewPercent { get; set; }
public virtual Register Register { get; set; }
}
public class RegisterConfiguration : EntityConfig<Register>
{
public RegisterConfiguration(bool useIdentity, bool sqlServerCe)
: base(sqlServerCe)
{
this.HasKey(t => t.Id);
if (!useIdentity)
{
Property(d => d.Id).IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
}
this.Property(t => t.Number).IsRequired().HasMaxLength(20);
}
}
public class CustomerDisplayConfiguration: EntityConfig<CustomerDisplay>
{
public CustomerDisplayConfiguration(bool sqlServerCe)
: base(sqlServerCe)
{
this.HasKey(t => t.RegisterId);
this.HasRequired(t => t.Register).WithMany().HasForeignKey(d => d.RegisterId).WillCascadeOnDelete(false);
}
}
我遇到了以下错误: 我在stackoverflow看到了很多相关的问题,但没有找到解决方案。其中这个问题最符合我的情况: 请问有谁能告诉我如何解决这个问题?谢谢