Nhibernate Criteria: 'select max(id)…'

后端 未结 3 1304
攒了一身酷
攒了一身酷 2021-01-02 08:28

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

O

3条回答
  •  无人及你
    2021-01-02 08:56

    Use Projection:

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

提交回复
热议问题