title: How to write a generic expression tree for filter data in c#
body: <p>Hi  I Create a winform Application in c#.</p>
  
  <p>I use EF5 to work with database.</p>
  
  <p>and for bind data to my datagridviews i created a component from BindingSource that has a Bind() method that run this event:</p>
  
  <pre><code>private object bindingSourceTbl1_DataSourceBinding(object sender, EventArgs e)
  {
      using (SampleDbEntities dbo = new SampleDbEntities())
      {
        return(from x in dbo.Tbl1
               where x.Id == (int)comboBoxPerson.SelectedValue
               select x).Take(1000).ToList();
      }
  }
  </code></pre>
  
  <p>because my database has  many large data i fetch partial of data.
  and i use search for get match record. for this i created a SearchPanel component that create textboxes for filter each columns in my grid.</p>
  
  <p>at now i want to send an expression tree to my event as a parameter to join to where clause like this:</p>
  
  <pre><code>private object bindingSourceTbl1_DataSourceBinding(object sender, EventArgs e,Expression whereClause)
  {
      using (SampleDbEntities dbo = new SampleDbEntities())
      {
        return(from x in dbo.Tbl1
               where x.Id == (int)comboBoxPerson.SelectedValue &amp;&amp; whereClause
               select x).Take(1000).ToList();
      }
  }
  </code></pre>
  
  <p>but my expression tree builder method exists in my component code and i dont access to my DbContext in my project and just i have fieldNames in my component, also i want to write just one method for all tables.</p>
  
  <p>this means i can't return like </p>
  
  <blockquote>
    <p>Expression&lt; Func&lt; AnyDbSet,bool>></p>
  </blockquote>
  
  <p>and i don't know how do it?</p>
  
  <p>Thanks</p>