title: How to make a method generic when "type 'T' must be a reference type"?
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/1992443/why-do-i-get-error-must-be-a-reference-type-in-my-c-generic-method">Why do I get “error: … must be a reference type” in my C# generic method?</a></p>
  </blockquote>
  
  <p>I have 2 Repository methods that are almost identical:</p>
  <pre><code>public IList&lt;Fund&gt; GetFundsByName(int pageSize, string searchExpression)
  {
      return _session.CreateCriteria&lt;Fund&gt;()
          .AddNameSearchCriteria&lt;Fund&gt;(searchExpression)
          .AddOrder&lt;Fund&gt;(f =&gt; f.Name, Order.Asc)
          .SetMaxResults(pageSize).List&lt;Fund&gt;();
  }
  
  public IList&lt;Company&gt; GetCompaniesByName(int pageSize, string searchExpression)
  {
      return _session.CreateCriteria&lt;Company&gt;()
          .AddNameSearchCriteria&lt;Company&gt;(searchExpression)
          .AddOrder&lt;Company&gt;(f =&gt; f.Name, Order.Asc)
          .SetMaxResults(pageSize).List&lt;Company&gt;();
  }
  </code></pre>
  <p>The only difference is that the first one's <code>_session.CreateCriteria</code> is of type <code>Fund</code> and the second one is <code>company</code></p>
  <p>I was hoping that I could make this generic by changing the method definition to:</p>
  <pre><code>public IList&lt;T&gt; GetEntitiesByName&lt;T&gt;(int pageSize, string searchExpression)
      where T : ISearchableEntity
  {
      return _session.CreateCriteria&lt;T&gt;()
          .AddNameSearchCriteria&lt;T&gt;(searchExpression)
          .AddOrder&lt;T&gt;(f =&gt; f.Name, Order.Asc)
          .SetMaxResults(pageSize).List&lt;T&gt;();
  }
  </code></pre>
  <p>where ISearchableEntity is defined as:</p>
  <pre><code>public interface ISearchableEntity
  {
      string Name { get; set; }
  }
  </code></pre>
  <p>but unfortunately NHibernate doesn't like this and gives me the error:</p>
  <p><code>The type 'T' must be a reference type in order to use it as parameter 'T' in the generic type or method 'NHibernate.ISession.CreateCriteria&lt;T&gt;()'</code></p>
  <p>Is it possible for me to make this generic some other way?</p>