title: ASP.NET Dynamic Linq Search
body: <pre>
  
  var query = (from u in results
              select u).AsQueryable();
  
  
  //Build where clause
  if (!string.IsNullOrEmpty(userRequest.searchData))
  {
      if (userRequest.searchBy == "LastName")
      {
          var likestr = userRequest.searchData.Trim();
          query = (from n in query where n.StartsWith(likestr) select n).AsQueryable();
  
      }
      if (userRequest.searchBy == "FirstName")
      {
  
      }
      if (userRequest.searchBy == "Email")
      {
          //var likestr = string.Format("%{0}%", userRequest.searchData.Trim());
  
      }
      if (userRequest.searchBy == "UserId")
      {
          query = query.Where(x => SqlMethods.Equals(x.UserId, Convert.ToInt32(userRequest.searchData)));
      }
  }
  
  </pre>
  
  <p>First I query the DB and store in var query.</p>
  
  <p>Then if there is search data I am trying to tack on the Where clause using 1 or 4 possible searches. </p>
  
  <p>Help?</p>