我正在构建患者预约预约系统并使用实体框架的代码优先方法。我设计了模型及其关系。有人可以告诉我是否有任何不正确的地方吗?
我假设以下是关系。如果我错了请纠正我
一位患者可以有多个预约,而一个预约只能属于一位患者。因此,患者与约会具有一对多的关系。
一位从业者可以有多个约会,而一个约会只能属于一位从业者。因此,Practioner 与约会具有一对多的关系。
一个 Practioner 可以有多个 PractionerTypes(例如 Doctor、Nurse),而一个 PractionerType 只能属于一个 Practioner。因此 Practioner 与 PractionerTypes 有一对多的关系。
一个 Appointment 可以有多个 AppointmentTypes(例如 Standard、Special),一个 AppointmentTypes 只能属于一个 Appointment 。因此 Appointment 与 AppointmentTypes 有一对多的关系。
一个 Practitioner 可以有多个 PractitionerAvailableHours,一个 PractitionerAvailableHours 只能属于一个 Practioner
看到这篇文章后我有点困惑http://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx
根据这篇文章,当你在做一对多关系时,你需要在一个类中定义多个类的属性,并在多个类中拥有一个类的集合属性。在他们的例子中。学生是一类,标准是多类。学生有标准类的虚拟属性方法,标准类有学生类的虚拟集合属性在我的设计中,正好相反。假设 Patient 和 Appointments 有一对多的关系
考虑到上述情况,实体设计如下所示
预约
public class Appointment
{
public int Id { get; set; }
public DateTime Date { get; set; }
public DateTime Time { get; set; }
public string Note { get; set; }
public virtual Patient Patient { get; set; }
public virtual Practioner Practioner { get; set; }
public int PatientId { get; set; }
public int PractionerId { get; set; }
public virtual ICollection<AppointmentType> AppointmentType { get; set; }
}
约会类型
public class AppointmentType
{
public int Id { get; set; }
public string Name { get; set; }
public virtual Appointment Appointment { get; set; }
public int AppointmentId { get; set; }
}
病人
public class Patient
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
public char Gender { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Postcode { get; set; }
public virtual ICollection<Appointment> Appointments { get; set; }
}
从业者
public class Practioner
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<Appointment> Appointments { get; set; }
public virtual ICollection<PractitionerAvailableHours> PractionerAvailableHours { get; set; }
}
从业者类型
public class PractionerType
{
public int Id { get; set; }
public string Name { get; set; }
public int PractionerId { get; set; }
public virtual Practioner Practioner { get; set; }
}
从业者可用时间
public class PractitionerAvailableHours
{
public int Id { get; set; }
public virtual Practioner Practioner { get; set; }
public int PractionerId { get; set; }
public DateTime AvailableDate { get; set; }
public int AvailableHours { get; set; }
}