Entity Framework Code First - two Foreign Keys from same table

后端 未结 6 1928
别那么骄傲
别那么骄傲 2020-11-22 03:40

I\'ve just started using EF code first, so I\'m a total beginner in this topic.

I wanted to create relations between Teams and Matches:

1 match = 2 teams (ho

6条回答
  •  梦如初夏
    2020-11-22 03:58

    It's also possible to specify the ForeignKey() attribute on the navigation property:

    [ForeignKey("HomeTeamID")]
    public virtual Team HomeTeam { get; set; }
    [ForeignKey("GuestTeamID")]
    public virtual Team GuestTeam { get; set; }
    

    That way you don't need to add any code to the OnModelCreate method

提交回复
热议问题