title: Include all navigation properties using Reflection in generic repository using EF Core
body: <p>I'm working on creating a generic repository for an EF Core project to avoid having to write CRUD for all models. A major roadblock I've hit is navigation properties not being loaded since Core doesn't yet support lazy loading and the generic class obviously can't define .Include statements for class specific properties.</p>
  <p>I'm trying to do something like this for my Get method to include all the properties dynamically:</p>
  <pre><code>public virtual T Get(Guid itemId, bool eager = false)
  {
      IQueryable&lt;T&gt; querySet = _context.Set&lt;T&gt;();
      
      if (eager)
      {
          foreach (PropertyInfo p in typeof(T).GetProperties())
          {
              querySet = querySet.Include(p.Name);
          } 
      }
      
      return querySet.SingleOrDefault(i =&gt; i.EntityId == itemId);
  }
  </code></pre>
  <p>But it throws an error when including properties that are not navigation properties.</p>
  <p>I found this answer which is about the same thing but its for EF 5 and involves methods that are not present in EF core:</p>
  <p><a href="https://stackoverflow.com/questions/17886725/ef5-how-to-get-list-of-navigation-properties-for-a-domain-object">EF5 How to get list of navigation properties for a domain object</a></p>
  <p>Is it possible to accomplish the same thing in EF Core?</p>