例如,如果我们有Match和Team类,则要定义比赛,我们需要一个球队,但是可以定义不匹配的球队。我们如何与Fluent Api提供这种关系?我们必须为此定义外键吗?
class Match{
public int Id { get; set; }
public int HomeTeamId { get; set; }
public int AwayTeamId { get; set; }
public Team AwayTeam { get; set; }
public Team HomeTeam { get; set; }
}
class Team{
public int Id { get; set; }
public ICollection<Match> MatchAwayTeams { get; set; }
public ICollection<Match> MatchHomeTeams { get; set; }
}