title: ASP.NET search form - dynamic Linq to SQL?
body: <p>I have a search form that allows users to search on several different fields in several different ways. Here is an example of my code.</p>
  
  <pre><code>var claims = from c in db.Claims select c;
  
  switch (ddlSearchField.Text)
  {
      case "StartsWith":
          claims = claims.Where(c =&gt; c.companyFileID.StartsWith(txtSearchBox.Text));
          break;
  
      case "Equals":
          claims = claims.Where(c =&gt; c.companyFileID == txtSearchBox.Text);
          break;
  
      case "Contains":
          claims = claims.Where(c =&gt; c.companyFileID.Contains(txtSearchBox.Text));
          break;
  }
  </code></pre>
  
  <p>I have about ten different fields that a user can search on so my outer switch statement is pretty large. There has to be a more elegant way to accomplish this. </p>