nhibernatet-sqlicriteria

Nhibernate Criteria: 'select max(id)...'


Can I use a Criteria to execute a t-sql command to select the max value for a column in a table?

'select @cus_id = max(id) + 1 from customers'

Ta

Ollie


Solution

  • Use Projection:

    session.CreateCriteria(typeof(Customer))
      .SetProjection( Projections.Max("Id") )
      . UniqueResult();