在我的架构设计中,我有 2 个表,它们由 2 个不同的键关联。我知道当它们是表的“Id”成员时,EF 如何神奇地创建外键,但我不太明白如何创建第二个关系。
注意:这个模式实际上还不存在;我将使用 codefirst 来创建它。
这是我正在尝试做的简单图表(粉红色的关系是我不确定如何在 codefirst 中实现的关系) NewClub.Id 是主键,所有 NEW_CLUB_ID 都是它的外键粉红色突出显示的列是相关的,但不是唯一的:
namespace NCB.Models
{
public sealed class NewClub
{
public NewClub()
{
//Related tables here
NewClubRecruitingTeams = new List<NewClubRecruitingTeam>();
NewClubRecruitingTeamDates = new List<NewClubRecruitingTeamDate>();
}
//Primary Key
public int Id { get; set; }
//Club Info
public string CreatorMasterCustomerId { get; set; }
public string ClubMasterCustomerId { get; set; }
public bool IsConverted { get; set; }
public string NewClubName { get; set; }
public string NewClubLocation { get; set; }
public string NewClubType { get; set; }
public DateTime? DateCreated { get; set; }
public DateTime? DateUpdated { get; set; }
// Related tables here
public virtual List<NewClubRecruitingTeam> NewClubRecruitingTeams { get; set; }
public virtual List<NewClubRecruitingTeamDate> NewClubRecruitingTeamDates { get; set; }
}
public class NewClubRecruitingTeamDate
{
//Primary Key
public int Id { get; set; }
//Foriegn Keys
public int NewClubId { get; set; }
public int NewClubRecruitingTeamTeamNumber { get; set; }
public DateTime? StartDateTime { get; set; }
public DateTime? EndDateTime { get; set; }
public DateTime? DateCreated { get; set; }
public DateTime? DateUpdated { get; set; }
public NewClub NewClub { get; set; }
public NewClubRecruitingTeam NewClubRecruitingTeam { get; set; }
}
public class NewClubRecruitingTeam
{
//Primary Key
public int Id { get; set; }
//Foreign Key
public int NewClubId { get; set; }
public int TeamNumber { get; set; }
public string TeamMemberName { get; set; }
public string TeamMemberEmail { get; set; }
public string TeamMemberPhone { get; set; }
public DateTime? DateCreated { get; set; }
public DateTime? DateUpdated { get; set; }
public NewClub NewClub { get; set; }
}
}