title: How can I map this navigation property?
body: <p>I have two collections.  The parent has many children, but also stores the most current child's id.</p>
  
  <pre><code>public class Foo 
  {
      public int Id { get; set; }
      public ICollection&lt;Bar&gt; Bars { get; set; }
  
      public int? CurrentBarId { get; set; }
  
      // adding this causes the error below
      public virtual CurrentBar CurrentBar { get; set; } 
  }
  
  public class Bar 
  {
      public int Id { get; set; }
      public int FooId { get; set; }
      public virtual Foo Foo { get; set; }
  }
  </code></pre>
  
  <p>When I add the CurrentBarId property everything is persisted correctly.  However, when I add the CurrentBar property an exception is thrown when the <em>Bar</em> is created.</p>
  
  <p>I get the exception:</p>
  
  <pre><code>{"Invalid column name 'Foo_Id'."}
  </code></pre>
  
  <p>How can I map this navigation property in the context?  </p>
  
  <p><strong>Update</strong></p>
  
  <p>I have played around with this a bit and ended up with:</p>
  
  <pre><code>modelBuilder.Entity&lt;Foo&gt;()
      .HasOptional(x =&gt; x.CurrentBar)
      .WithOptionalDependent()
      .Map(map =&gt;
      {
          map.ToTable("Bar").MapKey("CurrentBarId");
      });
  </code></pre>
  
  <p>Now I get the following error.  Is this in the right direction, or how should I be trying to do this?</p>
  
  <blockquote>
    <p>error 3034: Problem in mapping
    fragments starting at lines 213,
    442:An entity from one EntitySet is
    mapped to a row that is also mapped to
    an entity from another EntitySet with
    possibly different key. Ensure these
    two mapping fragments do not map two
    unrelated EntitySets to two
    overlapping groups of rows.</p>
  </blockquote>