title: C# Linq where clause as a variable
body: <p>I am trying to make a LINQ statement where the where clause comes from a variable. For example:</p>
  
  <pre><code>string whereClause = address.zip == 23456;
  var x = from something in someList where whereClause;
  </code></pre>
  
  <p>Is this possible? I cannot seem to get it to work. </p>
  
  <p>thanks,</p>
  
  <p>Update - my where clause is predefined and will be based on user input so I don't think this will work for me. Basically whereClause is not constructed in the method, it is a parameter of the method which does the LINQ. I didn't explain that well here is a better example:</p>
  
  <pre><code>public void doLnq(string whereClause)
  {
     var x = from something in someList where whereClause;
     dowork(x);
  }
  </code></pre>
  
  <p>Update - Just to sum up some of the suggestions and centralize everything. </p>
  
  <p>I cannot use a switch to generate the where clause because there are way to many possibilities. </p>
  
  <p>The dynamic linq post that a few of you have posted does look promising but i am having trouble related the linq to sql example to my linq to objects problem. </p>
  
  <p>and @sLaks after looking through msdn <a href="http://msdn.microsoft.com/en-us/library/bb353734.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/bb353734.aspx</a> I am having trouble figuring out where you meant to use AsQueryable</p>
  
  <p>thanks,</p>