title: How to use Entity Framework 4.1 Code First to force a one to one relationship for a one to many relationship in the database
body: <p>I am trying to change EF1 for EF4.1 code first in an application where the <strong>schema cannot be changed</strong> because it is used in SQL Server Replication. The schema is dreadfully poor and in many places describes relationships completely back to front.</p>
  
  <p>What I am trying to do is create a one to one relationship between two classes, but the database schema erroneously maintains the data as a one to many.</p>
  
  <pre><code>public class ClassA
  {
      public ClassB
      {
          get;
          set;
      }
  }
  </code></pre>
  
  <p>Unfortunately the table ClassB in the database has reference to ClassAId rather than ClassA having a ClassBId as shown here:</p>
  
  <pre><code>CREATE TABLE [dbo].[ClassA]
      [Id] [bigint] IDENTITY
  
  
  CREATE TABLE [dbo].[ClassB]
      [Id] [bigint] IDENTITY
      [ClassAId] [bigint]
  </code></pre>
  
  <p>How to I set up my mapping file that inherits from EntityTypeConfiguration to force this relationship.</p>
  
  <pre><code>public class ClassAMapping : EntityTypeConfiguration&lt;ClassA&gt;
  {
      public ClassA()
      {
          HasKey(f =&gt; f.Id);
  
          // what happens here to force a one to one????
      }
  }
  </code></pre>