title: Build IQueryable.Any with Expression Trees for LINQ queries
body: <p>I'm building a SQL &quot;WHERE&quot; clause dynamically using the System.Linq.Expressions.Expression class. It works well for simple clauses, e.g. to add &quot;PhaseCode = X&quot; clause, I do the following:</p>
  <pre><code>var equalTarget = Expression.Constant(phaseCode, typeof(int?));
  var phaseEquals = Expression.Equal(Expression.PropertyOrField(projParam, &quot;PhaseCode&quot;), equalTarget);
  </code></pre>
  <p>However, now I'm trying to build an expression that will return the record if a project has been assigned to a particular group. Project and Group has many-to-many relationship.
  Without the expression trees, I would do it as follows:</p>
  <pre><code>db.Projects.Where(p =&gt; .... &amp;&amp; p.GroupsAssigned.Any(g =&gt; g.ID == groupId))
  </code></pre>
  <p>However, I can't seem to find a way to express that with the Expression class.
  There are actually two things I can't figure out:</p>
  <ul>
  <li>How to traverse the relationships between tables</li>
  <li>How to do x.Any()</li>
  </ul>
  <p>Any help is greatly appreciated.</p>