今天,我有一个包含 40.000 个寄存器的列表,我需要将其保存在我的 MSSQL 数据库中。当我尝试保存它时,我检查了控制台显示,我意识到它正在逐项保存,并且消耗了大量时间,即使我尝试使用下面的命令插入整个列表也是如此。
List<Andamento> andamentoList = fillAndamentoList(parameters);
_repository.Save(andamentoList);
_repository.Commit();
是否可以配置 NHibernate 并将其更改为仅通过一次数据库交互来实际插入整个列表?
非常感谢,
对于使用 NHibernate 进行批处理,您需要使用无状态会话:
using (var statelessSession = sessionFactory.OpenStatelessSession())
using (var transaction = statelessSession.BeginTransaction())
{
foreach (var item in andamentoList)
{
statelessSession.Insert(item);
}
transaction.Commit();
}
将此与批量大小结合起来,以提高配置文件的性能:
<property name="adonet.batch_size">100</property>
您可以阅读更多内容here http://thatextramile.be/blog/2008/10/bulk-data-operations-with-nhibernates-stateless-sessions/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)