开发者

Code First CTP4: How to map these two entities

Let's say that I have two entities, Team and Match. In every Match, there are two teams, the HomeTeam and the AwayTeam. A Team can have many matches, but HomeTeam and AwayTeam can only have one team each. Sometimes Team is a HomeTeam, and sometimes the same Team is an AwayTeam. I have provided just the basics for each of the classes:

public class Team
{
    public int TeamId { get; set; }
    public stri开发者_JS百科ng Name { get; set; }
}



public class Match
{
        public int MatchId { get; set; }
        public int HomeTeamId { get; set; }
        public int AwayTeamId { get; set; }
}

How can I map this? I tried (with setting ICollection Matches and tried to map it, but I got that HomeTeam and AwayTeam can't have the same inverse relationship (something like that).

Thanks.


How about this?

public class Team
{
    public int TeamId { get; set; }
    public string Name { get; set; }
    public List<Match> Matches {get; set;}
}

public class Match
{
    public int MatchId { get; set; }
    public Team HomeTeamId { get; set; }
    public Team AwayTeamId { get; set; }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜