title: EF 4.3 relationships not right
body: <pre><code>public class ObjectA
  {
      public Guid Id {get; set;}
      public virtual ObjectB Objectb {get; set;}
  }
  
  public class ObjectB
  {
      public Guid Id {get; set;}
      public Guid ObjectAId {get; set;}
      public virtual ObjectA ObjectA {get; set;}
  }
  </code></pre>
  
  <p>I'm having no luck getting the relationships correct.</p>
  
  <pre><code>modelBuilder.Entity&lt;ObjectA&gt;()
      .HasRequired(p =&gt; p.ObjectB)
      .WithRequiredPrincipal()
      .WillCascadeOnDelete(false); 
  </code></pre>
  
  <p>Two relationships are created: </p>
  
  <ol>
  <li>Object.ObjectA/ObjectA.Id</li>
  <li>ObjectA.Id/ObjectB.Id</li>
  </ol>
  
  <p>How do I get EF to stop creating relationship #2? It's not correct and not what I want.</p>
  
  <p>Wrong:</p>
  
  <pre><code>modelBuilder.Entity&lt;ObjectA&gt;().HasRequired(x =&gt; x.Objectb).WithRequiredPrincipal(x =&gt; x.ObjectA);
  
      ALTER TABLE [dbo].[ObjectBs]  WITH CHECK ADD  CONSTRAINT [FK_ObjectBs_ObjectAs_Id] FOREIGN KEY([Id])
      REFERENCES [dbo].[ObjectAs] ([Id])
      GO 
  </code></pre>
  
  <p>Almost right:</p>
  
  <pre><code>modelBuilder.Entity&lt;ObjectA&gt;().HasOptional(x =&gt; x.Objectb).WithOptionalPrincipal(x =&gt; x.ObjectA);
  
  ALTER TABLE [dbo].[ObjectBs]  WITH CHECK ADD  CONSTRAINT [FK_ObjectBs_ObjectAs_ObjectA_Id] FOREIGN KEY([ObjectA_Id])
  REFERENCES [dbo].[ObjectAs] ([Id])
  GO
  </code></pre>
  
  <p>An additional column is added, so I end up with ObjectAId and ObjectA_Id in ObjectB.</p>
  
  <pre><code>modelBuilder.Entity&lt;ObjectA&gt;().HasOptional(x =&gt; x.Objectb).WithOptionalPrincipal(x =&gt; x.ObjectA).Map(x =&gt; x.MapKey("ObjectAId"));
  </code></pre>
  
  <p>Throws an exception: Each property name in a type must be unique. Property name 'ObjectAId' was already defined.</p>