title: Multiple foreign keys to same primary key table
body: <p>I have a table with multiple fields that are foreign keys to a primary key in another table.  For example :</p>
  
  <pre><code>Fixture Id (PK)
  HomeTeamId (FK to Team.TeamId)
  AwayTeamId (FK to Team.TeamId)
  HomeTeamCoachId (FK to Coach.CoachId)
  AwayTeamCoachId (FK to Coach.CoachId)
  </code></pre>
  
  <p>Would it be better to separate this data into 2 tables HomeTeam and AwayTeam with a foreign key to FixtureId?  This is currently what was generated by Entity Framework :</p>
  
  <pre><code>FixtureId PK
  HomeTeamId int
  AwayTeamId int
  HomeTeamCoachId int
  AwayTeamCoachId int
  AwayTeam_TeamId FK
  HomeTeam_TeamId FK
  AwayTeamCoach_CoachId FK
  HomeTeamCoach_CoachId FK
  </code></pre>
  
  <p>This was generated through this class :</p>
  
  <pre><code>public partial class Fixture
  {
      public int FixtureId { get; set; }
  
      //foreign key
      public int AwayTeamId { get; set; }
      //navigation properties
      public virtual Team AwayTeam { get; set; }
  
      //foreign key
      public int HomeTeamId { get; set; }
      //navigation properties
      public virtual Team HomeTeam { get; set; }
  
      //foreign key
      public int AwayCoachId { get; set; }
      //navigation properties
      public virtual Coach AwayCoach { get; set; }
  
      //foreign key
      public int HomeCoachId { get; set; }
      //navigation properties
      public virtual Coach HomeCoach { get; set; }
  }
  </code></pre>
  
  <p>Can anybody tell me if this is the correct way to do this?</p>
  
  <p>EDIT : In reply to Slauma </p>
  
  <p>So my classes would basically look like this?  Or does the configuration in OnModelCreating mean I don't need some of the foreign key related code in my Fixture class?</p>
  
  <pre><code> protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          // Entity Type Configuration
          modelBuilder.Configurations.Add(new TeamConfiguration());
          modelBuilder.Configurations.Add(new CoachConfiguration());
          modelBuilder.Configurations.Add(new FixtureConfiguration());
  
          modelBuilder.Entity&lt;Fixture&gt;()
              .HasRequired(f =&gt; f.AwayTeam)
              .WithMany()
              .HasForeignKey(f =&gt; f.AwayTeamId)
              .WillCascadeOnDelete(false);
  
          modelBuilder.Entity&lt;Fixture&gt;()
              .HasRequired(f =&gt; f.HomeTeam)
              .WithMany()
              .HasForeignKey(f =&gt; f.HomeTeamId)
              .WillCascadeOnDelete(false);
  
          modelBuilder.Entity&lt;Fixture&gt;()
              .HasRequired(f =&gt; f.AwayCoach)
              .WithMany()
              .HasForeignKey(f =&gt; f.AwayCoachId)
              .WillCascadeOnDelete(false);
  
          modelBuilder.Entity&lt;Fixture&gt;()
              .HasRequired(f =&gt; f.HomeCoach)
              .WithMany()
              .HasForeignKey(f =&gt; f.HomeCoachId)
              .WillCascadeOnDelete(false);
      }
  
  public partial class Fixture
  {
      public int FixtureId { get; set; }
      public string Season { get; set; }
      public byte Week { get; set; }
  
      //foreign key
      public int AwayTeamId { get; set; }
      //navigation properties
      public virtual Team AwayTeam { get; set; }
  
      //foreign key
      public int HomeTeamId { get; set; }
      //navigation properties
      public virtual Team HomeTeam { get; set; }
  
      //foreign key
      public int AwayCoachId { get; set; }
      //navigation properties
      public virtual Coach AwayCoach { get; set; }
  
      //foreign key
      public int HomeCoachId { get; set; }
      //navigation properties
      public virtual Coach HomeCoach { get; set; }
  
      public byte AwayTeamScore { get; set; }
      public byte HomeTeamScore { get; set; }
  }
  </code></pre>