title: How to customize foreign key column name using Entity Framework Code-first
body: <p>I have the following model</p>
  
  <pre><code>public class Foo
  {
      public int Id { get; set; }
      public IList&lt;Bar&gt; Bars { get; set; }
  }
  
  public class Bar
  {
      public int Id { get; set; }
  }
  </code></pre>
  
  <p>When I generate the database schema from this using EF Code first it creates the following tables:</p>
  
  <h2>Foo</h2>
  
  <ul>
  <li>Id (PK, int, not null)</li>
  </ul>
  
  <h2>Bar</h2>
  
  <ul>
  <li>Id (PK, int, not null)</li>
  <li>Foo_Id (FK, int null)</li>
  </ul>
  
  <p>Is it possible to change the name of the Foo_Id foreign key using attributes?</p>
  
  <p><strong>EDIT: Here is the version that does what I need:</strong></p>
  
  <pre><code>public class Foo
  {
      public int Id { get; set; }
  
      [ForeignKey("AssignedToBarId")]
      public IList&lt;Bar&gt; Bars { get; set; }
  }
  
  public class Bar
  {
      public int AssignedToBarId { get; set; }
      public int Id { get; set; }
  }
  </code></pre>