Batch Update in NHibernate

前端 未结 6 1142
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 09:04

Does batch update command exist in NHibernate? As far as I am aware it doesn\'t. So what\'s the best way to handle this situation? I would like to do the following:

6条回答
  •  伪装坚强ぢ
    2020-11-30 09:13

    You don't need to update, nor flush:

    IList users = session.CreateQuery (...).List;
    users.Foreach(u=>u.Country="Antartica")
    session.Transaction.Commit();
    

    I think NHibernate writes a batch for all the changes.

    The problem is, that your users need to be loaded into memory. If it gets a problem, you can still use native SQL using NHibernate. But until you didn't prove that it is a performance problem, stick with the nice solution.

提交回复
热议问题