nhibernate : executing updates in batches

后端 未结 3 1980
别那么骄傲
别那么骄傲 2021-01-26 18:58

I am trying to do batch updates using NHibernate, but it is not doing batch updates, its doing individual writes for all the rows. I have to write around 10k rows to db.

相关标签:
3条回答
  • 2021-01-26 19:32

    Note that:

    • Batches are not visible in Sql Server Profiler. Do not depend on that.
    • When inserting using identity (or native) id generators, NH turns off ado.net batch size.

    Additional notes:

    • make sure that you do not have a query for each changed entity, because it flushes before queries.
    • You probably should not call session.Update. In the best case, it doesn't do anything. In worst case, it really does updating thus breaking batching.

    When doing having many objects in the session, don't forget to care about flushes and flush time. Sometimes flushing is more time consuming than updating. NH flushes before commit, when you call flush and before queries, unless you turned it off or you use a stateless session. Make sure that you only flush once.

    0 讨论(0)
  • 2021-01-26 19:35

    nhibernate does not batch versioned entities that was the issue in my case.

    There is no way you can batch version entities, the only to do this is to make the entity non versioned.

    0 讨论(0)
  • 2021-01-26 19:38

    You are using a stateless session. Since a stateless session has no state, it cannot remember anything to do later. Hence the update is executed immediately.

    0 讨论(0)
提交回复
热议问题