实体框架代码-来自同一表的两个外键我刚开始使用EF代码,所以我完全是这个话题的初学者。我想在球队和比赛之间建立关系:1场比赛=2支球队(主场,客人)和结果。我认为创建这样的模型很容易,所以我开始编写代码: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]
3 回答
- 3 回答
- 0 关注
- 515 浏览
添加回答
举报
0/150
提交
取消