title: C# LINQ lambda expression with Contains as a method parameter
body: <p>I am writing a method that gets a lambda expression as a parameter to be used to filter the <code>IList&lt;SomeModel&gt; _collection</code>.</p>
  
  <pre><code>public void DoSomething(SomeModel model)
  {
     FilterCollectionUsingPredicate(x =&gt; x.Name.Equals(model.Name));
  }
  
  private void FilterCollectionUsingPredicate(Func&lt;SomeModel, bool&gt; predicate)
  {
     _collection = _collection.Where(predicate).ToList();
  }
  </code></pre>
  
  <p>It works well when the <code>predicate</code> parameter is a simple expression, like  <code>x =&gt; x.Name.Equals(model.Name)</code>. 
  However, it gets tricky when it has to use some other (local) collection and <code>Contains</code> clause.</p>
  
  <pre><code>public void DoSomething(SomeModel model)
  {
     IEnumerable&lt;string&gt; someOtherCollection = model.SomeOtherCollection;
     FilterCollectionUsingPredicate(x =&gt; someOtherCollection.Contains(x.Phone));
  }
  
  private void FilterCollectionUsingPredicate(Func&lt;SomeModel, bool&gt; predicate)
  {
     _collection = _collection.Where(predicate).ToList();
  }
  </code></pre>
  
  <p>Of course, <code>FilterCollectionUsingPredicate</code> method does not see <code>someOtherCollection</code> and therefore, throws an error.
  Can someone explain how to properly define and use this function to handle such a case?</p>