title: How To: Use LINQ to search data for a string containing many possible types of "Single Quote"
body: <p>The Problem:
  My customers want to be able to search for first and last names in my site, using any version of ', `, or those goofy microsoft 'start' and 'end' quotes.</p>
  
  <p>I would like to be able to write a single statement that looks for all possible permutations of that evil symbol, like such:</p>
  
  <pre><code>var customers = _sms.CurrentSession.Query&lt;customer&gt;()
                                     .Where(c =&gt; c.FirstName.Contains(firstName)
                                              &amp;&amp; c.LastName.Contains(lastName)
                                              &amp;&amp; !c.IsEmployee)
                                      .ToList();
  </code></pre>
  
  <p>and if the user was searching for "O'Brien", I would show them results for "O'Brien", and "O`Brien", and any other version of that stupid thing.</p>
  
  <p>What's the best way to do that? Is there a way to do it (without a massive recursion where I do things like</p>
  
  <pre><code>if (firstName.Contains("'")
  {
      var customers = _sms.CurrentSession.Query&lt;customer&gt;()
                                         .Where(c =&gt; c.FirstName.Contains(firstName)
                                                  &amp;&amp; c.LastName.Contains(lastName)
                                                  &amp;&amp; !c.IsEmployee)
                                      .ToList();
  
      firstName = firstName.Replace("'", "`");
      customers.AddRange(_sms.CurrentSession.Query&lt;customer&gt;()
                                         .Where(c =&gt; c.FirstName.Contains(firstName)
                                                  &amp;&amp; c.LastName.Contains(lastName)
                                                  &amp;&amp; !c.IsEmployee)
                                      .ToList());
  }
  </code></pre>
  
  <p>etc...</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>    private static readonly string[] Quotes = { "@", "'", "‘", "’", "`" };
      private IEnumerable&lt;customer&gt; CustomersByFirstName(string firstName, bool showInactive = true)
      {
          firstName = firstName.Replace(Quotes[1], Quotes[0]);
          var customers = _sms.CurrentSession.Query&lt;customer&gt;()
                              .Where(c =&gt; (c.FirstName.Replace(Quotes[1], Quotes[0]).Contains(firstName) ||
                                          c.FirstName.Replace(Quotes[2], Quotes[0]).Contains(firstName) ||
                                          c.FirstName.Replace(Quotes[3], Quotes[0]).Contains(firstName) ||
                                          c.FirstName.Replace(Quotes[4], Quotes[0]).Contains(firstName))
                                          &amp;&amp; !c.IsEmployee)
                              .ToList();
  
          if (!showInactive)
          {
              customers = customers.Where(c =&gt; !c.Disabled).ToList();
          }
  
          return customers;
      }
  </code></pre>
  
  <p>This is almost it... Almost</p>
  
  <p><strong>Final Update</strong>
  This turns out to be exactly the solution, tho not as elegant and small as I might like:</p>
  
  <pre><code>    private IEnumerable&lt;customer&gt; CustomersByFirstName(string firstName, bool showInactive = true)
      {
          firstName = firstName.Replace(Quotes[1], Quotes[0]);
          firstName = firstName.Replace(Quotes[2], Quotes[0]);
          firstName = firstName.Replace(Quotes[3], Quotes[0]);
          firstName = firstName.Replace(Quotes[4], Quotes[0]);
  
          var customers = _sms.CurrentSession.Query&lt;customer&gt;()
                              .Where(c =&gt; (c.FirstName.Replace(Quotes[1], Quotes[0]).Contains(firstName) ||
                                          c.FirstName.Replace(Quotes[2], Quotes[0]).Contains(firstName) ||
                                          c.FirstName.Replace(Quotes[3], Quotes[0]).Contains(firstName) ||
                                          c.FirstName.Replace(Quotes[4], Quotes[0]).Contains(firstName))
                                          &amp;&amp; !c.IsEmployee)
                              .ToList();
  
          if (!showInactive)
          {
              customers = customers.Where(c =&gt; !c.Disabled).ToList();
          }
  
          return customers;
      }
  </code></pre>