title: Entity Framework foreign key references not mapping
body: <p>Using EF6 and .NET 4.6.1. I know this somewhat is a duplicate (I've looked at <a href="https://stackoverflow.com/questions/17254724/the-principal-end-of-this-association-must-be-explicitly-configured-using-either">this stack overflow post</a>) but hear me out. My case is different and I have tried to get it to work using their solutions with mine but it didn't work. So no this isn't actually a duplicate. It's another issue altogether and I haven't found a post that really helps me on this topic.</p>
  
  <p>I am trying to map relationships between 3 models; <code>Employee</code>, <code>Position</code> and <code>Employment</code>. I want a one-to-many between <code>Employment</code> and <code>Position</code> (employments map to one position) and a one-to-one between <code>Employment</code> and <code>Employee</code>.</p>
  
  <pre><code>public class Employment
  {
      public int EmploymentID { get; set;}
      ...
      public Position Position { get; set; }
      public Employee Employee { get; set; }
  }
  
  public class Position
  {
      public int PositionID { get; set;}
      ...
      [InverseProperty("Position")]
      public ICollection&lt;Employment&gt; Employments { get; set; }
  }
  
  public class Employee
  {
      public int EmployeeID { get; set;}
      ...
      [InverseProperty("Employee")]
      public Employment Employment { get; set; }
  }
  </code></pre>
  
  <p>However, when I try to run this with <code>DbContext</code> automapping, it fails and says it can't find the relationships. I've tried multiple combinations of data annotations like setting inverseproperties and foreignkey("____ID") on some of them but haven't been able to get it to work.</p>
  
  <p>I did also try adding virtual keywords in for some of the but that didn't do anything either.</p>
  
  <p>I'd rather not use FluentAPI as I want to let the auto mapper do as much as possible with this. It's not complicated a problem enough to warrant manually mapping it with FluentAPI (At least in my opinion it isn't. Maybe I'm wrong).</p>
  
  <p>What data annotations do I need? I've looked at <a href="https://stackoverflow.com/questions/17254724/the-principal-end-of-this-association-must-be-explicitly-configured-using-either">this stack overflow post</a> and various articles on <a href="http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-first.aspx" rel="nofollow noreferrer">entityframeworktutorial.net</a> trying to apply their solutions to my case. But haven't gotten anything to work.</p>
  
  <p>The failing line is here:</p>
  
  <pre><code>using (EmploymentContext ctx = new EmploymentContext())
  {
      Position pos = new Position()
      {
          PositionID=1,
          Name="General Manager"
      };
      ctx.Positions.Add(pos); // Failing here
      ctx.SaveChanges();
  }
  </code></pre>
  
  <p>and the error message is:</p>
  
  <blockquote>
    <p>'Unable to determine the principal end of an association between the types <code>'Ianmann.Hr.DataAccess.Employment.Employee</code> and <code>Ianmann.Hr.DataAccess.Employment.Employment</code>. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.'</p>
  </blockquote>