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)
{
base.Save(o);
}
tx.Commit();
}
Session.NHibernateSession.SetBatchSize(0);
source
share