I try to enable the Bach Size in my SessionFactory:
Fluently.Configure()
.Database(MySQLConfiguration.Standard.AdoNetBatchSize(1)
.ConnectionString("xxx"))
.Mappings(m => m.FluentMappings.AddFromAssembly(...))
.ExposeConfiguration(c => c.SetProperty("adonet.batch_size", "1"))
.BuildSessionFactory();
but when I want to set the value of the batch size:
Session = _sessionFactory.OpenSession();
Session.SetBatchSize(25);
Session.FlushMode = FlushMode.Commit;
I still get that error:
No batch size was defined for the session factory, batching is disabled. Set adonet.batch_size = 1 to enable batching.
You should use
MySqlClientBatchingBatcherFactory
Thus, something like
Fluently.Configure()
.Database(MySQLConfiguration.Standard
.ConnectionString("xxx"))
.Mappings(m => m.FluentMappings.AddFromAssembly(...))
.ExposeConfiguration(c => c.DataBaseIntegration(prop =>
{
prop.BatchSize = 50;
prop.Batcher<MySqlClientBatchingBatcherFactory>();
}))
.BuildSessionFactory();
should work.
Please see these answers: Fluent NHibernate MySQL batching or MySQL NHibernate Batcher if you had further problems with batching; they show other ways to implement it.
Take into account that NHibernate prior to ¿4.0? did not support (natively) batching when combined with MySQL, and a external package was needed (due to some mysql dependencies). After this version, however, the batcher was included into the main trunk so these answers are still valid.
If you use NHibernate 4+, no problems should arise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With