title: EF 4.1 one to one Mapping
body: <p>I have two tables Employees and Positions. </p>
  
  <h2>Employee</h2>
  
  <p>EmployeeId (PK)</p>
  
  <p>PositionId (FK, Nullable)</p>
  
  <h2>Position</h2>
  
  <p>PositionId (PK)</p>
  
  <p>A position can be created and not be assigned. However, an active employee requires a position. A position can only be assigned to one employee. We enforce this by having a Unique Constraint on Employee.PositionId.</p>
  
  <p>In my models, I want to have an Employee property in Position and I am having issues mapping this.</p>
  
  <p>I've tried</p>
  
  <pre><code>modelBuilder.Entity&lt;Employee&gt;().HasRequired(e =&gt; e.Position)
                                 .WithOptional(p =&gt; p.Employee);
  </code></pre>
  
  <p>However this ends up mapping the Employee.EmployeeId to Position.PositionId column, instead of Employee.PositionId to Position.PositionId (at least from what I can tell...)</p>
  
  <p>Is my only option to make map this as a One to Many relationship even though I am forcing 1-1 through unique constraint?</p>