title: Expression tree nested wheres
body: <p>I am trying to dynamically build an expression tree that queries a datasource effectively using an in query. The query i am trying to replicate is </p>
  
  <pre><code>Countries.Where(y =&gt; Countries
                           .Where(x =&gt;
                               x.CountryLanguage.Any(b =&gt; b.CountryID == 73) &amp;&amp;
                               x.CountryLanguage.Any(b =&gt; b.CountryID == 150))
                           .Select(z =&gt; z.ShortCode)
                           .Contains(y.ShortCode))
  </code></pre>
  
  <p>I have tried many ways of doing this, but this is my latest attempt:</p>
  
  <pre><code>public void AddContainsWhereClause(IQueryable&lt;T&gt; objectSet, string predicateIdentifier)
  {
      ParameterExpression pe = Expression.Parameter(typeof(T), predicateIdentifier);
  
      Expression expInner = Expression.Call(
          typeof(Queryable),
          "Where",
          new Type[] { typeof(T) },
          objectSet.Expression,
          Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(rootExperession, resultExpression));
  
      Expression expOuter = Expression.Call(
          typeof(Queryable),
          "Where",
          new Type[] { typeof(T) },
          objectSet.Expression,
          Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(expInner, pe));
  
  }
  </code></pre>
  
  <p>NB rootExpression is:</p>
  
  <pre><code>x =&gt; x.CountryLanguage.Any(b =&gt; b.CountryID == 73) &amp;&amp;
       x.CountryLanguage.Any(b =&gt; b.CountryID == 150)
  </code></pre>
  
  <p>But this returns:</p>
  
  <blockquote>
    <p>[ApplicationFramework.LINQBuilder.tests.Country]' cannot be used for return type 'System.Boolean'</p>
  </blockquote>
  
  <p>Does anyone know what i am doing wrong?</p>