title: Pass LINQ expression as parameter to where clause
body: <p>Please read the question carefully before voting to close it. That is not a duplicate.</p>
  
  <p>I am trying to build a generic method that returns list of entities of type T joined to logs of type AuditLog. Here is a LEFT JOIN interpretation in LINQ that I use</p>
  
  <pre><code>var result = from entity in entitySet
               from auditLog in auditLogSet.Where(joinExpression).DefaultIfEmpty()
               select new { entity, auditLog };
  return result.GroupBy(item =&gt; item.entity)
                       .Select(group =&gt; new
                           {
                               Entity = group.Key,
                               Logs = group.Where(i =&gt; i.auditLog != null).Select(i =&gt; i.auditLog)
                           });
  </code></pre>
  
  <p>The problem is in <strong>joinExpression</strong>. I want to pass it to the WHERE clause, but it is different for different concrete types T (it is dependent on the <strong>entity</strong> variable), for example for a specific entity it could be</p>
  
  <pre><code>joinExpression = l =&gt; l.TableName == "SomeTable" &amp;&amp; l.EntityId == entity.SomeTableId;
  </code></pre>
  
  <p>Notice entity.SomeTableId above. This is the reason I can't initialize joinExpression before the beginning of the query.
  How can I pass joinExpression as a parameter if it is actually dependent on "entity" variable, which is part of the query itself?</p>