title: Combine Expressions instead of using multiple queries in Entity Framework
body: <p>I have following generic queryable (which may already have selections applied):</p>
  
  <pre><code>IQueryable&lt;TEntity&gt; queryable = DBSet&lt;TEntity&gt;.AsQueryable();
  </code></pre>
  
  <p>Then there is the <code>Provider</code> class that looks like this:</p>
  
  <pre><code>public class Provider&lt;TEntity&gt;
  {
      public Expression&lt;Func&lt;TEntity, bool&gt;&gt; Condition { get; set; }
  
      [...]
  }
  </code></pre>
  
  <p>The <code>Condition</code> could be defined per instance in the following fashion:</p>
  
  <pre><code>Condition = entity =&gt; entity.Id == 3;
  </code></pre>
  
  <p>Now I want to select all <code>Provider</code> instances which have a <code>Condition</code> that is met at least by one entity of the <code>DBSet</code>:</p>
  
  <pre><code>List&lt;Provider&gt; providers = [...];
  var matchingProviders = providers.Where(provider =&gt; queryable.Any(provider.Condition))
  </code></pre>
  
  <p>The problem with this: I'm starting a query for each <code>Provider</code> instance in the list. I'd rather use a single query to achieve the same result. This topic is especially important because of questionable performance. How can I achieve the same results with a single query and improve performance using <code>Linq</code> statements or <code>Expression Trees</code>?</p>