title: One-to-One relationship in Entity Framework Core
body: <p>I have been playing around with .NET Core for the past couple of weeks and decided to try EF Core (coming from ASP.NET MVC with NHibernate). After a bit of digging I found a nice extensions called <a href="https://marketplace.visualstudio.com/items?itemName=michaelsawczyn.EFDesigner" rel="nofollow noreferrer">EF Visual Designer</a>. It allows me to visually create the model and generate code.</p>
  <p>I have defined a simple one-to-one relationship shown in the diagram:
  <a href="https://i.stack.imgur.com/xaimQ.png" rel="nofollow noreferrer">Simple one-to-one relationship</a></p>
  <p>After generating the code I get the following as Fluent API code:</p>
  <pre><code>modelBuilder.Entity&lt;Authentication&gt;()
     .ToTable(&quot;Authentications&quot;)
     .HasKey(t =&gt; t.Id);
  
  modelBuilder.Entity&lt;Authentication&gt;()
      .Property(t =&gt; t.Id)
      .IsRequired()
      .ValueGeneratedOnAdd();
  
  modelBuilder.Entity&lt;User&gt;()
       .ToTable(&quot;Users&quot;)
       .HasKey(t =&gt; t.Id);
  
  modelBuilder.Entity&lt;User&gt;()
       .Property(t =&gt; t.Id)
       .IsRequired()
       .ValueGeneratedOnAdd();
  
  modelBuilder.Entity&lt;User&gt;()
      .HasOne(x =&gt; x.Authentication)
      .WithOne()
      .HasForeignKey(&quot;Authentication_Id&quot;)
      .IsRequired();
  </code></pre>
  <p>The user class has the following (relevant) properties:</p>
  <pre><code>public Class User {
      [Key]
      [Required]
      public Guid Id { get; set; }
      ...
      public virtual Authentication Authentication { get; set; }
  }
  </code></pre>
  <p>Authentication has the following (relevant) property:</p>
  <pre><code>public class Authentication  {
      [Key]
      [Required]
      public Guid Id { get; set; }
  }
  </code></pre>
  <p>However when I try to generate a migration I get the following error:</p>
  <blockquote>
  <p>You are configuring a relationship between 'User' and 'Authentication'
  but have specified a foreign key on
  'Authentication_Id'. The foreign key
  must be defined on a type that is part of the relationship.</p>
  </blockquote>
  <p>I tried switching to a many-to-one relationship and that works without any problems. That could be a work-around but not a very clean one. Is this perhaps due to naming issues like both entities having &quot;Id&quot; as primary key?</p>
  <p>If that's the case, what is the &quot;best practice&quot;? Do I give every entity a unique ID-column name? How do I go about an abstract entity with derived classes all inheriting the ID column?</p>