且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

EF code首先外键的

更新时间:2023-02-07 14:54:08

根据您的设​​置,人们AppointmentType只能有一个约会。这是一个一对一的映射。在这种情况下,你***移动AppointmentType到约会实体。否则,我相信更符合逻辑,一个AppoitmentType可以有很多,但任命一个约会只能有一个AppointmentType。因此,你应该有你的AppointmentType实体内部的一个虚拟的ICollection。

According to your setup, one AppointmentType can only have one Appointment. This is a one-to-one mapping. In this case, you better move the AppointmentType into the Appointment entity. Otherwise, what I believe is more logical, an AppoitmentType can have many Appointments but one Appointment can have only one AppointmentType. Accordingly, you should have a virtual ICollection inside your AppointmentType entity.

 public class AppointmentType
 {
      [ScaffoldColumn(false)]
      public int AppointmentTypeID { get; set; }

      [Required]
      public string Name { get; set; }
      public string Description { get; set; }

      public virtual ICollection<Appointment> Appointments { get; set; }
 }

我不知道这是什么造成的问题,但它可能是。有时候,映射故障导致引发一些奇怪的例外。给它一个尝试,让我知道,如果你的问题得到解决。

I am not sure this is what's causing the problem but it could be. Sometimes mapping faults cause some weird exceptions to be thrown. Give it a try and let me know if your problem gets resolved.