title: nhibernate queryover LIKE with expression trees
body: <p>I'm looking to add a method to my base repository class that allows me to use <strong>LIKE</strong> expressions but I'm not quite sure of how to go about this.  I want to create a generic method that looks at the expression tree passed in and looks for wildcard characters in the string values passed in.  It would then generate the <code>QueryOver</code> statement accordingly.  </p>
  
  <p>I have the following currently:  </p>
  
  <pre><code>public IList&lt;T&gt; FindAll(Expression&lt;Func&lt;T, bool&gt;&gt; criteria, char wildCard)
  {
      return SessionFactory.GetCurrentSession()
              .QueryOver&lt;T&gt;()
              .Where(criteria)
              .List();
  }
  </code></pre>
  
  <p>Obviously the hard part is yet to come.  I need to look through the expression tree and build the query using <code>QueryOver</code> dynamically. Looking for some pointers on how to proceed with this. Or am I just wasting my time here and should just create individual methods in my repositories that handle the <strong>LIKE</strong> queries?</p>
  
  <h3> Additional Criteria </h3>
  
  <p>Ideally I'd like to tell the difference between the following:  </p>
  
  <ul>
  <li>search*</li>
  <li>*search</li>
  <li>*search*</li>
  </ul>
  
  <p>So the query generated would be:  </p>
  
  <ul>
  <li>field LIKE 'search%'</li>
  <li>field LIKE '%search'</li>
  <li>field LIKE '%search%'</li>
  </ul>