title: NHibernate Select Max value with filter
body: <p>I am trying to get the max value from a table, doing something like this:</p>
  
  <pre><code>        SELECT max(re.Sequence) FROM MyTable re WHERE re.ItemId = :itemId
  </code></pre>
  
  <p>So i can get for each itemId the maximum value for the column Sequence.</p>
  
  <p>Tried with createQuery but didn´t worked:</p>
  
  <pre><code>        string hql = @"SELECT new Int32(max(re.Sequence) FROM MyTable re WHERE re.Item.Id = :itemId";
          List&lt;Int32&gt; lista =  session
              .CreateQuery(hql)
              .SetParameter("itemId", idItem)
              .List&lt;Int32&gt;()
              .ToList();
  </code></pre>
  
  <p>Any help will be appreciated.</p>
  
  <p>Best Regards.</p>