title: AndAlso between several Expression<Func<T, bool>> : referenced from scope
body: <p>I have 3 predicates, I'd like make an <code>AndAlso</code> between. I found several sample on the board, but can't solve my problem.</p>
  
  <p>These predicates are : <code>Expression&lt;Func&lt;T, bool&gt;&gt;</code></p>
  
  <p>I have this code :</p>
  
  <pre><code>Expression&lt;Func&lt;T, bool&gt;&gt; predicate1 = ......;
  Expression&lt;Func&lt;T, bool&gt;&gt; predicate2 = ......;
  Expression&lt;Func&lt;T, bool&gt;&gt; predicate3 = ......;
  </code></pre>
  
  <p>I create an extension method to make an "AndAlso" :</p>
  
  <pre><code>public static Expression&lt;Func&lt;T, bool&gt;&gt; AndAlso&lt;T&gt;(
      this Expression&lt;Func&lt;T, bool&gt;&gt; expr, 
      Expression&lt;Func&lt;T, bool&gt;&gt; exprAdd)
  {
      var param = Expression.Parameter(typeof(T), "p");
      var predicateBody = Expression.AndAlso(expr.Body, exprAdd.Body);
      return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(predicateBody, param);
  
      //Tried this too
      //var body = Expression.AndAlso(expr.Body, exprAdd.Body);
      //return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(body, expr.Parameters[0]);
  }
  </code></pre>
  
  <p>I use like this :</p>
  
  <pre><code>var finalPredicate = predicate1
      .AndAlso&lt;MyClass&gt;(predicate2)
      .AndAlso&lt;MyClass&gt;(predicate3);
  </code></pre>
  
  <p>The predicate look this :
  <img src="https://i.stack.imgur.com/i8oPz.png" alt="enter image description here"></p>
  
  <p>When I use in a query :</p>
  
  <pre><code>var res =  myListAsQueryable().Where(finalPredicate).ToList&lt;MyClass&gt;();
  </code></pre>
  
  <p>I get this error :
  <em>variable 'p' of type 'BuilderPredicate.MyClass' referenced from scope '', but it is not defined</em></p>
  
  <p>Could you tell me what's wrong ?</p>
  
  <p>Thanks a lot,</p>