title: Entity Framework Code First - two Foreign Keys from same table
body: <p>I've just started using EF code first, so I'm a total beginner in this topic.</p>
  
  <p>I wanted to create relations between Teams and Matches:</p>
  
  <p>1 match = 2 teams (home, guest) and result. </p>
  
  <p>I thought it's easy to create such a model, so I started coding:</p>
  
  <pre><code>public class Team
  {
      [Key]
      public int TeamId { get; set;} 
      public string Name { get; set; }
  
      public virtual ICollection&lt;Match&gt; 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; }
  }
  </code></pre>
  
  <p>And I get an exception: </p>
  
  <blockquote>
    <p>The referential relationship will result in a cyclical reference that is not allowed. [ Constraint name = Match_GuestTeam ]</p>
  </blockquote>
  
  <p>How can I create such a model, with 2 foreign keys to the same table?</p>