title: C# - How to use Expression<Func> with parametrs in LINQ where
body: <p>Task: I need to give some expression with parameters into <code>LINQ's</code> where to get some data from <code>database</code>, but have an error above
  This example of working expression:</p>
  
  <pre><code>var shopExp = GetPersonForShop(PersonTypeIds.Director, new Guid("adda423f-8c38-40e0-9f39-6deceb787bc0")); // id
  Where(shopExp) 
  </code></pre>
  
  <p>But i need assign id dynamically, but got error above :</p>
  
  <pre><code>_repository.Persons
  .Where(GetPersonForShop(PersonTypeIds.Director, person.PersonId)
  </code></pre>
  
  <p>And got error:</p>
  
  <blockquote>
    <p>{"Unable to cast object of type 'System.Linq.Expressions.InstanceMethodCallExpression2' to type 'System.Linq.Expressions.LambdaExpression'."}</p>
  </blockquote>
  
  <p>How does function for where(linq) look:</p>
  
  <pre><code>private Expression&lt;Func&lt;Person, bool&gt;&gt; GetPersonForShop(PersonTypeIds personTypeId, Guid personId)
          {
              return person =&gt; person .PeronTypeId== (int) personTypeId &amp;&amp; person .PersonId == personId;
          }
  </code></pre>
  
  <p>This is approximate look like out production, just change names of parametrs code</p>
  
  <p>How can I add expression with parameters to <code>Where</code> clause??</p>