title: Linq to sql, using like in dynamic where clause
body: <p>I need to use <code>LIKE</code> operators in a dynamic <code>WHERE</code> clause.</p>
  
  <p>I am currently using <code>=</code> operators but need to replace with <code>LIKE</code> :</p>
  
  <pre><code>String whereClause = "1 = 1 AND ";
  whereClause = whereClause + (search.Id != null ? "Id = " + search.Id + " AND " : "");
  whereClause = whereClause + (search.FirstName != null ? "FirstName = \"" + search.FirstName + "\" AND " : "");
  whereClause = whereClause + (search.LastName != null ? "LastName = \"" + search.LastName + "\" AND " : "");
  whereClause = whereClause + (search.StudentName != null ? "StudentName = \"" + search.StudentName + "\" AND " : "");
  whereClause = whereClause + (search.Country != null ? "CountryLabel = \"" + search.Country + "\" AND " : "");
  whereClause = whereClause + (search.ZipCode != null ? "ZipCode = \"" + search.ZipCode + "\" AND " : "");
  whereClause = whereClause + (search.City != null ? "City = \"" + search.City + "\" AND " : "");
  whereClause = whereClause.Remove(whereClause.Length - 5);
  
  IEnumerable&lt;MyClassDto&gt; res = (
      from ...
      where ...
      select new MyClassDto() {
          ...
      }
  ).Where(whereClause);
  </code></pre>
  
  <ol>
  <li>I cannot use <code>Contains()</code>, <code>StartsWith()</code> or <code>EndsWith()</code> as search parameters can be in the form "%my%value".</li>
  <li>I cannot manage to use <code>SqlMethods.Like()</code> in dynamic <code>WHERE</code> clause.</li>
  <li>I don't want to include it in the <code>WHERE</code> clause of the <code>MyClassDto</code> query as it slow down the execution time, it is why I apply another <code>WHERE</code> clause on the <code>Enumerable</code>, matching only search parameters.</li>
  </ol>
  
  <p>Any suggestions ?</p>