title: Entity Framework Core: model's related entity is being saved but won't load
body: <p>I have a model <code>PlayerContext</code> which has one entity of type <code>Inventory</code> (which is a derived type of <code>ItemContainer</code>). These are all within my <code>DbContext</code> called <code>ChunkContext</code>. When I create a new <code>PlayerContext</code> a <code>Inventory</code> is also constructed and both are saved in the database with the correct ID's and everything (I can confirm by looking in the DB). For some reason when I load the <code>PlayerContext</code> later (after it's been saved) the <code>Inventory</code> is not being loaded (it has the default value and ID of 0 which is incorrect).
  Here is how I'm loading the player (and adding to them to the database if they are a new player):</p>
  <pre><code>        using (var db = new ChunkContext())
          {
              PlayerContext playerContext = db.Players
                  .Where(p =&gt; p.username == username)
                  .Include(p =&gt; p.inventory)
                  .FirstOrDefault();
              // this means the player couldn't be grabbed from the DB
              if (playerContext == null)
              {
                  playerContext = new PlayerContext();
                  playerContext.username = username;
                  db.Players.Add(playerContext);
                  db.SaveChanges();
              }
              return new Player(peer, playerContext);
          }
  </code></pre>
  <p>And here is all of the model classes:</p>
  <pre><code>class ChunkContext : DbContext
  {
      ...
      public DbSet&lt;PlayerContext&gt; Players { get; set; }
      ...
      public DbSet&lt;ItemContainerContext&gt; ItemContainers { get; set; }
      public DbSet&lt;Inventory&gt; Inventories { get; set; }
      ...
  
  protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          ...
          modelBuilder.Entity&lt;PlayerContext&gt;().HasOne(p =&gt; p.inventory);
          ...
          modelBuilder.Entity&lt;ItemContainerContext&gt;().HasKey(ic =&gt; ic.id);
          ...
          base.OnModelCreating(modelBuilder);
      }
  </code></pre>
  <p>_</p>
  <pre><code>[Index(nameof(username), IsUnique = true)]
  public class PlayerContext
  {
      public PlayerContext()
      {
          inventory = new Inventory();
      }
      ...
  
      [Key]
      public int id { get; set; }
      ...
  
      [Required]
      public Inventory inventory { get; set; }
      ...
  }
  </code></pre>
  <p>_</p>
  <pre><code>public class Inventory : ItemContainerContext
  {
      ... unrelated gameplay code ...
  }
  </code></pre>
  <p>_</p>
  <pre><code>public class ItemContainerContext
  {
      [Key]
      public int id { get; set; }
  
      public ItemContainerContext()
      {
          ...
      }
  
      ...
  }
  </code></pre>