title: EntityFramework Eager Load all Navigation Properties
body: <p>I'm using the Repository pattern with DI and IoC.</p>
  
  <p>I have created a function in my Repository:</p>
  
  <pre><code>T EagerGetById&lt;T&gt;(Guid id, string include) where T : class
  {
      return _dbContext.Set&lt;T&gt;().Include(include).Find(id);
  }
  </code></pre>
  
  <p>This will eagerly load one navigation property in my entity right.</p>
  
  <p>But if my entity looks like this:</p>
  
  <pre><code>public class Blog : PrimaryKey
  {
      public Author Author {get;set;}
      public ICollection&lt;Post&gt; Posts {get;set;}
  }
  </code></pre>
  
  <p>How would I get eager loading for <code>Author</code> and <code>Posts</code>? Would I literally have to do:</p>
  
  <pre><code>_dbContext.Set&lt;T&gt;().Include("Author").Include("Posts").Find(id);
  </code></pre>
  
  <p>inevitably producing a function like this:</p>
  
  <pre><code>T EagerGetById&lt;T&gt;(Guid id, string include, string include2, string include3) where T : class
  {
      return _dbContext.Set&lt;T&gt;().Include(include).Include(include2).Include(include3).Find(id);
  }
  </code></pre>
  
  <p>Because that would be really inefficient for a <code>Generic</code> Repository!</p>