title: EF Core w/ Sql Server one-to-many relationship not working
body: <p>I'm trying to create a simple RESTful API that can retrieve information from a Sql Server DB. I'm using .Net Core, together with EF Core for ORM.</p>
  
  <p>I have mapped two tables in my database by foreign key. However, when i try to implement the relationship in EF core, it seems that no rows exist in the BaseStats table that reference the given champion row in the Champions table.</p>
  
  <p>I get the following result when making the API call:</p>
  
  <pre><code>{
  "championId": 1,
  "championName": "Vladimir",
  "baseStats": null
   }
  </code></pre>
  
  <p>It seems that EF core somehow doesn't recognize the relationship. I must have missed something.</p>
  
  <p>Any advice would be greatly appreciated :) Below is my code. Thanks in advance.</p>
  
  <p><strong>Principal entity:</strong></p>
  
  <pre><code>public class Champion
  {
      public int ChampionId                  { get; set; }
      public string ChampionName             { get; set; }
  
      public ICollection&lt;BaseStat&gt; BaseStats { get; set; }
  }
  </code></pre>
  
  <p><strong>Dependent entity</strong></p>
  
  <pre><code>public class BaseStat
  {
      public int      BaseStatId { get; set; }
      public int      StatTypeId { get; set; }
      public decimal  Base       { get; set; }
      public decimal  Growth     { get; set; }
  
      public Champion Champion   { get; set; }
  }
  </code></pre>
  
  <p><strong>DB context</strong></p>
  
  <pre><code>public class Context : DbContext
  {
      public DbSet&lt;Champion&gt;  Champions { get; set; }
      public DbSet&lt;BaseStat&gt;  BaseStats { get; set; }
  
      public Context(DbContextOptions&lt;Context&gt; options) : base (options)
      {
          //
      }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;BaseStat&gt;()
              .HasOne(p =&gt; p.Champion)
              .WithMany(b =&gt; b.BaseStats);
      }
  
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>[Route("api/[controller]/[action]")]
  public class ChampionController : Controller
  {
  
      private readonly Context _context;
  
      public ChampionController(Context context)
      {
          _context = context; 
      }
  
      public async Task&lt;JsonResult&gt; Stats()
      {
          var champ = await _context.Champions.FirstOrDefaultAsync(c =&gt; c.ChampionId == 1);
          return Json(champ);
      }
  
  }
  </code></pre>