title: combine predicates into expression
body: <p>I am aiming to use this signature:</p>
  
  <pre><code>IEnumerable&lt;T&gt; SearchFor(Expression&lt;Func&lt;T, bool&gt;&gt; expression);
  </code></pre>
  
  <p>and would like to AND these 2 predicates:</p>
  
  <pre><code>Func&lt;Employee, bool&gt; isActiveEmployee = e =&gt; e.DateFired == null;
  Func&lt;Employee, bool&gt; isNewEmployee = e =&gt; e.DateHired &gt;= DateTime.Today.AddDays(-90);
  </code></pre>
  
  <p>into an expression. How can I achieve this please?</p>
  
  <p>PS:</p>
  
  <p>Basically, I am trying to use <a href="http://www.bradoncode.com/blog/2013/05/orms-don-reinvent-wheel.html" rel="nofollow">this</a>. But the line:</p>
  
  <pre><code>var body = (BinaryExpression) expression.Body;
  </code></pre>
  
  <p>in method <code>GetDynamicQuery</code> taken from <a href="https://github.com/bbraithwaite/RepoWrapper/blob/master/DynamicQuery.cs" rel="nofollow">here</a> throws an exception:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Linq.Expressions.InstanceMethodCallExpressionN' to type 'System.Linq.Expressions.BinaryExpression'.</p>
  </blockquote>
  
  <p>Using this approach:</p>
  
  <pre><code>Expression&lt;Func&lt;Employee, bool&gt;&gt; isActiveEmployee = e =&gt; e.DateFired == null;
  Expression&lt;Func&lt;Employee, bool&gt;&gt; isNewEmployee = e =&gt; e.DateHired &gt;= DateTime.Today.AddDays(-90);
  
  Expression&lt;Func&lt;Employee, bool&gt;&gt; combined_expression = e =&gt; isActiveEmployee.Invoke(e) &amp;&amp; isNewEmployee.Invoke(e);
  </code></pre>