title: LINQ to Entity, using a SQL LIKE operator
body: <p>I have a LINQ to ENTITY query that pulls from a table, but I need to be able to create a "fuzzy" type search. So I need to add a where clause that searches by lastname IF they add the  criteria in the search box (Textbox, CAN be blank --- in which case it pulls EVERYTHING).</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>    var query = from mem in context.Member
                  orderby mem.LastName, mem.FirstName
                  select new
                  {
                      FirstName = mem.FirstName,
                      LastName = mem.LastName,
  
                  };
  </code></pre>
  
  <p>That will pull everything out of the Member table that is in the Entity object.</p>
  
  <p>Then I have an addition to the logic:</p>
  
  <pre><code>sLastName = formCollection["FuzzyLastName"].ToString();
  
  if (!String.IsNullOrEmpty(sLastName))
     query = query.Where(ln =&gt; ln.LastName.Contains(sLastName));
  </code></pre>
  
  <p>The problem is when the search button is pressed, nothing is returned (0 results). I have run the query against the SQL Server that I expect to happen here and it returns 6 results.</p>
  
  <p>This is the query I expect:</p>
  
  <pre><code>SELECT mem.LastName, mem.FirstName FROM Members mem WHERE mem.LastName LIKE '%xxx%'
  </code></pre>
  
  <p>(when xxx is entered into the textbox)</p>
  
  <p>Anyone see anything wrong with this?</p>
  
  <p>EDIT: Fixed the SELECT query. I meant for it to read LIKE '%xxx%' (NOT = 'xxx")</p>