【问题标题】:Fluent nHibernate - can't set the batch sizeFluent nHibernate - 无法设置批量大小
【发布时间】:2015-02-25 14:12:51
【问题描述】:

我尝试在我的 SessionFactory 中启用 Bach Size:

Fluently.Configure()
        .Database(MySQLConfiguration.Standard.AdoNetBatchSize(1)
        .ConnectionString("xxx"))
        .Mappings(m => m.FluentMappings.AddFromAssembly(...))
        .ExposeConfiguration(c => c.SetProperty("adonet.batch_size", "1"))
        .BuildSessionFactory();

但是当我想设置批量大小的值时:

Session = _sessionFactory.OpenSession();

Session.SetBatchSize(25);
Session.FlushMode = FlushMode.Commit;

我仍然收到该错误:

没有为会话工厂定义批处理大小,批处理是 禁用。设置 adonet.batch_size = 1 以启用批处理。

【问题讨论】:

    标签: c# fluent-nhibernate


    【解决方案1】:

    你应该使用

    MySqlClientBatchingBatcherFactory
    

    因此,像

        Fluently.Configure()
        .Database(MySQLConfiguration.Standard
        .ConnectionString("xxx"))
        .Mappings(m => m.FluentMappings.AddFromAssembly(...))
         .ExposeConfiguration(c => c.DataBaseIntegration(prop =>
        {
            prop.BatchSize = 50;
            prop.Batcher<MySqlClientBatchingBatcherFactory>();
    
        }))
        .BuildSessionFactory();
    

    应该可以。

    请查看以下答案:Fluent NHibernate MySQL batchingMySQL NHibernate Batcher,如果您在批处理方面还有其他问题;他们展示了实现它的其他方法。

    考虑到 ¿4.0 之前的 NHibernate?与 MySQL 结合时不支持(本机)批处理,并且需要外部包(由于某些 mysql 依赖项)。然而,在这个版本之后,批处理器被包含在主干中,所以这些答案仍然有效。

    如果您使用 NHibernate 4+,应该不会出现问题。

    【讨论】:

      猜你喜欢
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      相关资源
      最近更新 更多