I am trying to update several records with a database through NHibernate.
The direct SQL query looks like:
update records set sortOrder = sortOrder +1 where sortOrder >= 3 and sortOrder <= 100
Is this possible in NHibernate? I don’t want to take the approach of pulling each record and updating them one at a time since this method can be used on databases with several thousand records.
It sounds like you just want to send a command to the DB to do the update. If that’s the case, you can use the CreateSQLQuery method on the session object to do so. More info here.
If you are trying to persist multiple objects at once, you’ll need to do a batch update. More info on this from here.