可以通过在Game模型中添加两个外键关系来解决该问题。以下是一个代码示例:
public class Competitor { public int CompetitorId { get; set; } public string Name { get; set; } }
public class Game { public int GameId { get; set; } public string Name { get; set; }
public int Competitor1Id { get; set; }
public int Competitor2Id { get; set; }
[ForeignKey("Competitor1Id")]
public Competitor Competitor1 { get; set; }
[ForeignKey("Competitor2Id")]
public Competitor Competitor2 { get; set; }
}
在Game模型中,我们添加了两个外键关系,分别指向两个竞争者。我们还需要将这些属性标记为外键关系,并将它们映射到正确的Competitor实体。这样,我们就可以轻松地在游戏模型中引用两个竞争者。