title: Loading Related Data with Entity Framework Core
body: <p>I am creating a new project with ASP.NET Core &amp; Entity Framework Core. (I think this is entity framework 7?)</p>
  
  <p>I think MS have removed Lazy Loading, so my virtual collections are not loading automatically. So then I decided to try ".include" however this method was missing. So I included "System.Data.Entity" and now I have .include but it still loads the collections as null. The entites definitely have related data with in the database.</p>
  
  <p>My Code is as follows:</p>
  
  <pre><code>//Property Table
  public class Property
  {
      public int Id { get; set; }
  
      public string PropertyName { get; set; }
  
      public string Address1 { get; set; }
  
      public string Address2 { get; set; }
  
      public string City { get; set; }
  
      public string Postcode { get; set; }
  
      public string State { get; set; }
  
      public string Country { get; set; }
  
      public string PhoneNumber { get; set; }
  
      public virtual ICollection&lt;BodyCorpMember&gt; BodyCorpMembers { get; set; }
  
      public bool Deleted { get; set; }
  }
  
  //Body Corp Table
  public class BodyCorpMember
  {
      public int Id { get; set; }
  
      public string FirstName { get; set; }
  
      public string LastName { get; set; }
  
      public string Email { get; set; }
  
      public bool IsSecretary { get; set; }
  
      public int Property_Id { get; set; }
  
      [ForeignKey("Property_Id")]
      public virtual Property Property { get; set; }
  }
  </code></pre>
  
  <p>This is some of the things I tried in OnModelCreating with no success
          //builder.Entity()
          //    .HasOne(a => a.Property)
          //    .WithMany(a => a.BodyCorpMembers)
          //    .HasForeignKey("Property_Id");</p>
  
  <pre><code>    //builder.Entity&lt;Property&gt;()
      //    .HasMany(a =&gt; a.BodyCorpMembers)
      //    .WithOne(a =&gt; a.Property);
  
  
  
      //Here is my main problem, Ive tried multiple options for ".include"   but it always returns null for BodyCorpMembers
            property = _dbContext.Properties.Include(a=&gt;a.BodyCorpMembers).Where(a=&gt;a.Id ==id).FirstOrDefault();
  </code></pre>
  
  <p>it should also be noted that I am using the built in IdentityDbContext as my Db Context. ie:</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  </code></pre>