title: EF Fluent API - Nullable FK for one-to-many on same table
body: <p>I need to create a nullable foreign key for one-to-many relationship on the same table:</p>
  
  <pre><code>public class NavigationMenu
  {
  
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
  
      public NavigationMenu()
      {
          MenuChildren = new HashSet&lt;NavigationMenu&gt;();
      }
  
      public string Text { get; set; }
      public string Action { get; set; }
      public string Controller { get; set; }
      public string Icon { get; set; }
      public bool Selected { get; set; }
  
      public int? NavigationMenuId { get; set; }
  
      public virtual ICollection&lt;NavigationMenu&gt; MenuChildren { get; set; }
  
      public virtual NavigationMenu NavigationMenus2 { get; set; }
  
  }
  </code></pre>
  
  <p>with Fluent Api but i don't know which definition is correct, this:</p>
  
  <pre><code>modelBuilder.Entity&lt;NavigationMenu&gt;()
              .HasOptional(c =&gt; c.NavigationMenus2)
              .WithMany(c =&gt; c.MenuChildren)
              .HasForeignKey(c =&gt; c.NavigationMenuId);
  </code></pre>
  
  <p>or:</p>
  
  <pre><code> modelBuilder.Entity&lt;NavigationMenu&gt;()
              .HasMany(e =&gt; e.MenuChildren)
              .WithOptional(e =&gt; e.NavigationMenus2)
              .HasForeignKey(e =&gt; e.NavigationMenuId);
  </code></pre>