title: Accessing child object from parent object in EF Core
body: <p>I've searched the whole net, but still I can't get this to work.</p>
  
  <p>What I need is a simple list that looks like this:</p>
  
  <ul>
  <li><strong>ParentName1</strong></li>
  <li>ChildName1</li>
  <li>ChildName2</li>
  <li><strong>ParentName2</strong></li>
  <li>ChildName3</li>
  </ul>
  
  <p>I have one table of the Parent objects and one of the Child objects. In the table of Child objects, there is a foreign key ParentId.</p>
  
  <p>Now, I use strongly typed ViewModel and Intellisense even suggests the Child properties through a Parent.Child.Property, but then when I run the program I get a "NullReferenceException: Object reference not set to an instance of an object.".</p>
  
  <p><em>My Parent class looks like this:</em></p>
  
  <pre><code>    public class EmployeeArea
      {
          [Key]
          [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
          public int ID { get; set; }
  
          public int? StudioCode { get; set; }
  
          public string AreaName { get; set; }
  
          public List&lt;EmployeeName&gt; EmployeeNames { get; set; }
      }
  }
  </code></pre>
  
  <p><em>And my Child class looks like this:</em></p>
  
  <pre><code>    public class EmployeeName
      {
          [Key]
          [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
          public int ID { get; set; }
  
          public string Name { get; set; }
  
          public int AreaId { get; set; }
      }
  }
  </code></pre>
  
  <p>Do I need to do something in the DbContext ModelBuilder? I welcome any help. Thank you!</p>