实体框架代码-来自同一表的两个外键
public class Team{ [Key] public int TeamId { get; set;} public string Name { get; set; } public virtual ICollection<Match> Matches { get; set; }}public class Match{ [Key] public int MatchId { get; set; } [ForeignKey("HomeTeam"), Column(Order = 0)] public int HomeTeamId { get; set; } [ForeignKey("GuestTeam"), Column(Order = 1)] public int GuestTeamId { get; set; } public float HomePoints { get; set; } public float GuestPoints { get; set; } public DateTime Date { get; set; } public virtual Team HomeTeam { get; set; } public virtual Team GuestTeam { get; set; }}
引用关系将导致不允许的周期性引用。[约束名称=Match_GuestTeam]