【问题标题】:Fluent Nhibernate - How to persist collection of new entities with single database callFluent Nhibernate - 如何通过单个数据库调用持久化新实体的集合
【发布时间】:2010-10-04 19:08:47
【问题描述】:

我有一个创建多个新实体的过程。我尝试将它们添加到集合中(对它们执行 .Persist()),然后当我的集合准备就绪时,尝试提交事务。

我已检查以确保在调用 Transaction.Commit() 之前没有执行任何数据库调用,但是一旦调用 commit,我就会看到正在为每个单独的实体进行调用。

有没有办法一次保存所有相同类型的实体?

【问题讨论】:

    标签: c# nhibernate fluent


    【解决方案1】:

    您是否设置了批量大小?

    http://ayende.com/Blog/archive/2006/09/16/BatchingSupportInNHibernate.aspx

    在您的流利配置中尝试设置

    .AdoNetBatchSize(10)

    http://fluentnhibernate.org/api/FluentNHibernate.Cfg.Db/PersistenceConfiguration%602.htm

    希望这对你有帮助。

    【讨论】:

    • 请注意,执行批处理的能力还取决于您的特定数据库提供商。例如,这在 SQLite 中是不可能的(AFAIK)。
    【解决方案2】:

    如果您使用 Identity 作为主键,也适用于插入 Nhibernate 将无法批量插入。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      相关资源
      最近更新 更多