【发布时间】:2018-07-15 19:08:17
【问题描述】:
我正在开发一个系统,志愿者可以申请成为教堂仪式/约会的一部分。
我想拥有它,以便多个志愿者可以参加一个仪式,可能是 1 人,也可能是 4 人。我在 SO 上看到过各种示例,它们只使用两个外键,但我无法理解两个以上。我知道我需要逆属性,但我很困惑。
这是我需要的两个实体。我想我需要在志愿者中作为 ICollection 进行预约/仪式。我可能还差得很远,我不太确定。
public class Volunteer
{
[Key]
public int VolunteerId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public bool GardaVetted { get; set; }
public string VolunteerRole { get; set; }
public string VolunteerPhoneNumber { get; set; }
[ForeignKey("Church")]
public int ChurchId { get; set; }
[ForeignKey("Appointments")]
public int AppointmentId { get; set; }
//Foreign Key
public virtual Church Church { get; set; }
public virtual ICollection<Appointments> Appointments { get; set; }
}
public class Appointments
{
[Key]
public int AppointmentId { get; set; }
public string DetailsOfAppointment { get; set; }
public int? Fee { get; set; }
public string RoomType { get; set; }
public string NameOfApplicant { get; set; }
public string ApplicantPhoneNumber { get; set; }
public string ApplicantEmail { get; set; }
[DataType(DataType.DateTime)]
[DisplayFormat(ApplyFormatInEditMode = true,DataFormatString = "{0:dd/MM/yyyy HH:mm}")]
public DateTime DateOfAppointment { get; set; }
public string ThemeColour { get; set; }
public Boolean Confirmed { get; set; }
[ForeignKey("Admins")]
public int AdministrationId { get; set; }
[ForeignKey("Church")]
public int ChurchId { get; set; }
//[ForeignKey("Volunteers")]
//public int VolunteerId { get; set; }
public virtual Church Church { get; set; }
public virtual Administration Admins { get; set; }
//public virtual Volunteer Volunteers { get; set; }
}
【问题讨论】:
-
不太确定这与 sql server 或数据库设计有什么关系。发布的所有内容都是 dotnet 代码。
-
@SeanLange 我的错,更改了标签
-
@AnnaDoe 您可能还想添加一个实体框架标签
-
您是否打算允许一个志愿者有多个约会,以及一个涉及多个志愿者的约会?如果是这样,那么快速搜索
entity framework many-to-many relationship应该会有所帮助 -
是的,正如 Andrew 所说,这听起来更像是多对多。在每一侧放置一个集合,EF 将进行链接。你也有一个与教堂有联系的志愿者?这是正确的,还是您只想将活动与教堂联系起来?
标签: c# asp.net entity-framework orm ef-code-first