title: error when using linqkit's predicate with an expression method
body: <p><strong>A little background:</strong><br>
  I'm using a Linq provider (<a href="http://msdn.microsoft.com/en-us/library/ff681573.aspx" rel="nofollow">MsCrm2011 Linq provider</a>, but doesn't really matter) that doesn't support certain operations.<br>
  Specifically, it doesn't support <code>Contains()</code> inside an expression.<br>
  Meaning- something like this will not work: <code>var users = DataContext.Users.Where(user =&gt; userIds.Contains(user.Id))</code>.   </p>
  
  <p><a href="http://www.crmcodex.com/2011/12/tip-getting-around-a-contains-issue-in-linq-for-mscrm2011/" rel="nofollow">The solution I've found</a> for it was to use <a href="http://www.albahari.com/nutshell/linqkit.aspx" rel="nofollow">LinqKit</a>'s predicate, so instead of <code>userIds.Contains(...)</code> I'll have <code>user.Id == userIds[0] || user.Id == userIds[1] ... || user.Id == userIds[100]</code>.  </p>
  
  <p>To this end, I've defined the following function, which takes an arbitrary collection and arbitrary expression, and applies the 'Or' on them:  </p>
  
  <pre><code>private IQueryable&lt;TCrmEntity&gt; FilterByCollection&lt;TCrmEntity, T&gt;(IQueryable&lt;TCrmEntity&gt; entities, IEnumerable&lt;T&gt; collection, Expression&lt;Func&lt;TCrmEntity, T, bool&gt;&gt; filterFunction)
      {
        var predicate = PredicateBuilder.False&lt;TCrmEntity&gt;();
        predicate = collection.Aggregate(predicate, (current, collectionElement) =&gt; current.Or(entity =&gt; filterFunction.Invoke(entity,collectionElement)));
  
        var query = entities.AsExpandable()
          .Where(predicate);
  
        return query;
      }
  </code></pre>
  
  <p>this way, I can use any kind of collection and any kind of expression.<br>
  For example, see this test run (using an in-memory users collection): <code>var res = FilterByCollection(users.AsQueryable(), rolesList, (account, role) =&gt; account.Role == role)</code> to find all users that have one of the given roles.  </p>
  
  <p>However, I'm getting the following exception when I'm running the above example- <code>variable 'entity' of type 'User' referenced from scope '', but it is not defined</code>.  </p>
  
  <p>Any ideas?  </p>
  
  <p>P.S. not sure how relevant this is, but when I'm actually using the Crm data context instead of an in-memory collection, I'm not getting this error. :/</p>