title: Mapping foreign key in HasOptional().WithOptionalDependent() relation in Entity Framework 6
body: <p>I have the following data-model in Entity Framework 6.1.3:</p>
  
  <pre><code>using System.Data.Entity;
  
  public class Student
  {
      public int Id { get; set; }
      public virtual Contact Contact { get; set; }
  }
  
  public class Contact
  {
      public int Id { get; set; }
      public virtual Student Student { get; set; }
  }
  
  public class MyContext : DbContext
  {
      protected override void OnModelCreating(DbModelBuilder builder)
      {
          builder.Entity&lt;Contact&gt;()
              .HasOptional(x =&gt; x.Student)
              .WithOptionalDependent(x =&gt; x.Contact)
              .WillCascadeOnDelete(true);
      }
  }
  
  public static class Program
  {
      private static void Main()
      {
          Database.SetInitializer(new DropCreateDatabaseAlways&lt;MyContext&gt;());
  
          using (var context = new MyContext())
              context.Database.Initialize(force: true);
      }
  }
  </code></pre>
  
  <p>When I launch this code, I get exactly the right table structure I am aiming for:</p>
  
  <pre><code>dbo.Contacts
      Id (PK)
      Student_Id (FK, NULL, CASCADE ON DELETE)
  
  dbo.Students
      Id (PK)
  </code></pre>
  
  <p>However, now I would like to add the <code>Student_Id</code> property to be available in the <code>Contact</code> entity. So I can read the <code>Student_Id</code> without needing to join the other table through <code>.Student.Id</code> navigation.</p>
  
  <p>If I add the property to the <code>Contact</code> entity, I end up either with two columns <code>Student_Id</code> and <code>Student_Id1</code>, or I end up with an error message saying <code>Each property name in a type must be unique.</code>.</p>
  
  <p>The column is already in the database, all I need is to have it in the entity as well, why is it so much trouble? Is there a solution?</p>