Fluent NHibernate SetBatchSize method
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 usin开发者_运维百科g Fluent Nhibernate
Thnx
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);
I figured it out. Problem was in IdentityGenerator. It was set to AutoIdentity (SQL Server). As soon as I changed it to HiLo it started working.
精彩评论