title: Entity Framework 4.1 Code First Foreign Key Id's
body: <p>I have two entities referenced one to many. When entity framework created the table it creates two foreign keys, one for the key I have specified with the fluent interface and the other for the ICollection. How do I get rid of the duplicate foreign key?</p>
  
  <pre><code>public class Person
  {
      public long RecordId { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Email { get; set; }
      public string Username { get; set; }
  
      public long DepartmentId { get; set; }
      public virtual Department Department { get; set; }
  }
  
  public class Department
  {
      public long RecordId { get; set; }
      public string Name { get; set; }
  
      public virtual ICollection&lt;Person&gt; People { get; set; }
  }
  
  protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      modelBuilder.Entity&lt;Person&gt;()
          .HasRequired(p =&gt; p.Department)
          .WithMany()
          .HasForeignKey(p =&gt; p.DepartmentId)
          .WillCascadeOnDelete(false);
  }
  </code></pre>
  
  <p>Thanks!</p>