title: loading related entities from .NET Core EF using Code First
body: <p>I am trying to load related entities using .NET Core EF and Code First, however I am getting the following error :-</p>
  
  <pre><code>System.InvalidOperationException: The property 'Roles' is not a navigation property of entity type 'ApplicationUser'. The 'Include(string)' method can only be used with a '.' separated list of navigation property names.
  </code></pre>
  
  <p>My 2 models look as follows</p>
  
  <pre><code>public class Role
  {
      public short Id { get; set; }
      public string Name { get; set; }
  
      public ICollection&lt;ApplicationUser&gt; Users { get; set; }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class ApplicationUser
  {
      public long Id { get; set; }
  
      [Required(ErrorMessage = "This field is required")]
      public string Name { get; set; }
      [Required(ErrorMessage = "This field is required")]
      public string Surname { get; set; }
      public string HomeNo { get; set; }
      public string MobNo { get; set; }
      public short RoleId { get; set; }
  
      public string UserName { get; set; }
      [RegularExpression(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", ErrorMessage = "Invalid Email Address")]
      public string Email { get; set; }
      public string Password { get; set; }
  
      public Role Role { get; set; }
  </code></pre>
  
  <p>my Context looks as follows :-</p>
  
  <pre><code>        modelBuilder.Entity&lt;Role&gt;().ToTable("Role");
  
          modelBuilder.Entity&lt;ApplicationUser&gt;().HasOne(c =&gt; c.Role)
                                          .WithMany(r =&gt; r.Users)
                                          .HasForeignKey(c =&gt; c.RoleId);
          modelBuilder.Entity&lt;ApplicationUser&gt;().ToTable("ApplicationUser");
  </code></pre>
  
  <p>and I am trying to get the verifiedUser in a method as follows:-</p>
  
  <pre><code>   var verifiedUser = await GetById&lt;ApplicationUser&gt;(m =&gt; m.Email == user.Email, "Roles");
  </code></pre>
  
  <p>which in turn calls a GenericService :-</p>
  
  <pre><code>    public async Task&lt;T&gt; GetById&lt;TKey&gt;(
          Expression&lt;Func&lt;T, bool&gt;&gt; filter = null,
          string includeProperties = "")
      {
          return await _genericRepository.Get&lt;T&gt;(filter, includeProperties);
      }
  </code></pre>
  
  <p>and finally the GenericRepository:-</p>
  
  <pre><code>    public async Task&lt;T&gt; Get&lt;TKey&gt;(Expression&lt;Func&lt;T, bool&gt;&gt; filter = null, string includeProperties = "")
  
      {
          IQueryable&lt;T&gt; query = Context.Set&lt;T&gt;();
          query = IncludePropertiesQuery(query, includeProperties);
  
          if (filter != null)
          {
              query = query.Where(filter);
          }
  
          return await query.SingleOrDefaultAsync();
      }
  </code></pre>
  
  <p>The IncludePropertiesQuery looks like this :-</p>
  
  <pre><code>    private IQueryable&lt;T&gt; IncludePropertiesQuery(IQueryable&lt;T&gt; query, string includeProperties = "")
      {
          if (includeProperties == null)
          {
              includeProperties = "";
          }
  
          includeProperties = includeProperties.Trim() ?? string.Empty;
          foreach (var includeProperty in includeProperties.Split
              (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
          {
              query = query.Include(includeProperty);
          }
  
          return query;
  
      }
  </code></pre>
  
  <p>Is it something to do with my DbContext and the relationship I have between the 2 tables?</p>
  
  <p>Thanks for your help and time</p>