title: How can I include a predicate along with Included properties?
body: <p>Currently I have a function that allows me to query the database while including some other related tables in the results to prevent a return hit to the database that I know would occur otherwise if I don't:</p>
  
  <pre><code>public class EntityRepository&lt;TEntity&gt; : IEntityRepository&lt;TEntity&gt; where TEntity : class
  {
      protected DbSet&lt;TEntity&gt; dbSet;
  
      private readonly DbContext dc;
  
      public EntityRepository()
      {
          dc = new DbContext(Utility.Config.GetEntityDbConnection());
          dbSet = dc.Set&lt;TEntity&gt;();
      }
  
  
      public IQueryable&lt;TEntity&gt; GetAllIncluding(params Expression&lt;Func&lt;TEntity, object&gt;&gt;[] includeProperties)
      {
              foreach (var includedProperty in includeProperties)
              {
                  dbSet.Include(includedProperty).Load();
              }
  
              return dbSet;
      }
  }
  </code></pre>
  
  <p>However, I need to be able to also use a where clause prior to the include so that it doesn't try to query the entire database when it fires the <code>Load()</code> method.</p>
  
  <p>I was trying to do something like this (which obviously doesn't work because you can reassign <code>dbset</code> like in my sample code below).</p>
  
  <pre><code>    public IQueryable&lt;TEntity&gt; SearchForIncluding(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate, params Expression&lt;Func&lt;TEntity, object&gt;&gt;[] includeProperties)
      {
             dbset = dbSet.Where(predicate);  //THIS DOESN'T WORK OBVIOUSLY
  
             foreach (var includedProperty in includeProperties)
             {
                  dbSet.Include(includedProperty).Load();
             }
      }
  </code></pre>