title: EF5 one-to-one without navigation
body: <p>I'm trying to do a one-to-one relationship, with the navigation property just on one side (MVC4, EF5, code first).</p>
  
  <pre><code>public class User {
  
    public int UserId { get; set; } //PK
  
    public int RankId { get; set; } //FK
  
    public virtual Rank { get; set; } //Navigation
  
  }
  
  public class Rank {
  
    public int RankId { get; set; }
  
  }
  </code></pre>
  
  <p>Configuration:</p>
  
  <pre><code> public class RankConfiguration : EntityTypeConfiguration&lt;Rank&gt;
  {
      public RankConfiguration()
      {
        HasKey(e =&gt; e.RankId);
        Property(e =&gt; e.RankId)
          .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
      }
  }
  
  public class UserConfiguration : EntityTypeConfiguration&lt;User&gt;
  {
      public UserConfiguration ()
      {
        // PK
        HasKey(e =&gt; e.UserId);
  
        Property(e =&gt; e.RankId)
          .IsRequired();
  
        HasRequired(e =&gt; e.Rank)
          .WithRequiredDependent()
          .WillCascadeOnDelete(true);
      }
  }
  </code></pre>
  
  <p>For what I see (and for the little I know), db is correctly generated, but I get this error:</p>
  
  <p>A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'UserId'.</p>
  
  <p>In a first try, I was thinking to create a join table (ref. here <a href="https://stackoverflow.com/questions/14977947/ef5-fluent-api-one-to-one-without-navigator">EF5 Fluent API one-to-one without navigator</a>), don't know if was a good idea but I wasn't able to do with fluent API.</p>
  
  <p>I have no idea why and what is wrong .. any help? many thanks in advance</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><strong>First try</strong>
  After <a href="https://stackoverflow.com/a/14997417/1016255">@soadyp</a> comment, I tried to configure a one-to-one with a join table</p>
  
  <pre><code>HasRequired(e =&gt; e.Rank)
      .WithRequiredDependent()
      .Map(m =&gt;
      {
        m.ToTable("UserRank");
        m.MapKey("RankId");
      })
      .WillCascadeOnDelete(true);
  </code></pre>
  
  <p>but I get this error when I try to migrate:</p>
  
  <pre><code>The specified table 'UserRank' was not found in the model. 
  Ensure that the table name has been correctly specified.
  </code></pre>
  
  <p><strong>Second try</strong>
  Probably I'm making a simple job too complicated, after reading this <a href="http://weblogs.asp.net/manavi/archive/2011/04/14/associations-in-ef-4-1-code-first-part-3-shared-primary-key-associations.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/manavi/archive/2011/04/14/associations-in-ef-4-1-code-first-part-3-shared-primary-key-associations.aspx</a> I just changed in this way</p>
  
  <pre><code>  HasRequired(e =&gt; e.Rank)
      .WithOptional()
      .WillCascadeOnDelete(true);
  </code></pre>
  
  <p>Everything is fine, BUT the UserId PK wasn't setted as Identity (with obvious problmes when I insert a row). If I specify it as Identity:</p>
  
  <pre><code>  Property(e =&gt; e.UserId)
      .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Cascading foreign key 'FK_dbo.Users_dbo.Ranks_UserId' cannot be created where 
  the referencing column 'Users.UserID' is an identity column.
  Could not create constraint. See previous errors.
  </code></pre>