views:

113

answers:

1

I'm using NHibernate Profiler to see if batching really occurs. Code looks like this

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

Profiler still gives me error "Large number of individual writes".

BTW Im using Fluent Nhibernate

Thnx

A: 

I dislike leaving things like batch size to chance so I make sure I batch everything when saving inside an explicit transaction and it seems to do the 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); 
mhenrixon