title: Where clause on dynamic column name in LINQ query?
body: <p>I've created a dropdown with some column names in a table in my db. When a user selects a column name i want to add a where clause to the query to use this filter.</p>
  
  <p>What i'm trying to do is:</p>
  
  <pre><code>Dim objQuery = (From wc In _dbBellen.dealer_telefonies Order By wc.Bedrijfsnaam Select wc)
  
  'if dropdown has value...
  
  objQuery = objQuery.Where(Function(wc) wc.DynamicColumnName &lt; txtFilterValue1.Text)
  </code></pre>
  
  <p>The wc.DynamicColumnName has to be replaced by for example wc.Price.</p>
  
  <p>--</p>
  
  <p>The code what i'm tried now after some replies is:</p>
  
  <pre><code>    Dim objQuery = (From wc In _dbBellen.dealer_telefonies Order By wc.Bedrijfsnaam Select wc)
  
          If ddlFilterColumn1.SelectedValue &lt;&gt; "" And ddlFilterOperator1.SelectedValue &lt;&gt; "" And txtFilterValue1.Text &lt;&gt; "" Then
  
              Select Case ddlFilterOperator1.SelectedValue
                  Case "..%"
                      objQuery = objQuery.Where(Function(wc) wc.WHMCSClient_id Like txtFilterValue1.Text &amp; "%")
                  Case "%.."
                      objQuery = objQuery.Where(Function(wc) wc.WHMCSClient_id Like "%" &amp; txtFilterValue1.Text)
                  Case Else '&lt; &gt; = &lt;&gt;
                      'objQuery = objQuery.Where(Function(wc) wc.WHMCSClient_id &lt; txtFilterValue1.Text)
                      'objQuery = objQuery.Where(Function(wc) "wc." + ddlFilterColumn1.SelectedValue.ToString + " &lt; " + txtFilterValue1.Text)
                      objQuery = objQuery.Where(Function(wc) "wc.WHMCSClient_id &lt; 500")
              End Select
  
          End If
  
      Response.Write(objQuery.ToString())
  </code></pre>
  
  <p>But i am getting the following error (original error is in dutch but it said as follow): 
  The conversion from string wc.WHMCSClient_id &lt; 500 to type Boolean is invalid.</p>