Free NHibernate SetBatchSize Method

I use the NHibernate Profiler to see if batch processing is really happening. The code is as follows

Session.NHibernateSession.SetBatchSize(data.Items.Count); 
    foreach (var o in data.Items) 
    { 
        //something else... 
        base.Save(o); 
    } 
    Session.NHibernateSession.SetBatchSize(0); 

The profiler still gives me the error "A large number of individual entries."

BTW Im Using Fluent Nhibernate

Thnx

+3
source share
2 answers

I don’t like leaving things like batch size randomly, so I do whatever it takes to save inside an explicit transaction, and it seems like a trick for me.

Session.NHibernateSession.SetBatchSize(data.Items.Count); 
Session.NHibernateSession.FlushMode = FlushMode.Commit;
using (var tx = Session.NHibernateSession.BeginTransaction())
{
  foreach (var o in data.Items) 
  { 
      //something else... 
      base.Save(o); 
  }
  tx.Commit();
}
Session.NHibernateSession.SetBatchSize(0); 
+2
source

I get it. The problem was with IdentityGenerator. It has been configured for AutoIdentity (SQL Server). As soon as I changed it to HiLo, it started working.

+1

Source: https://habr.com/ru/post/1729531/


All Articles