NHibernate的批量大小不工作

NHibernate的批量大小不工作

本文介绍了NHibernate的批量大小不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在NHibernate的批量大小(C# - VS 2012)的一个问题。
我设置批量大小集合中,并在配置,但它不能正常工作。

I've got a problem with batch-size in nHibernate(C# - VS 2012).I set "batch-size" in the collection and in the config, but it doesn't work.

using (var s = OpenSession())
        {
            using (var t = s.BeginTransaction())
            {
                Parent parent = s.CreateCriteria(typeof(Parent)).List<Parent>().First();
                Console.Write(parent.Children[0]);
                t.Commit();
            }
        }



NHibernate的探查表明,它需要所有的孩子一下子( 。例如1000儿童),但它应该只5

nHibernate profiler shows that it takes all children at once (for example 1000 children), but it should take only 5.

Parent.hbm.xml:

Parent.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="L6.Model" assembly="L6">
  <class name="Parent">
    <id name="ParentId">
      <generator class="native" />
    </id>
    <bag name="Children" batch-size="5">
      <key column="ID_Parent"/>
      <one-to-many class="Child"/>
    </bag>
  </class>
</hibernate-mapping>



Child.hbm.xml:

Child.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="L6.Model" assembly="L6">
  <class name="Child">
    <id name="ChildId">
      <generator class="native" />
    </id>
    <many-to-one name="Parent" column="ID_Parent" class="Parent" />
  </class>
</hibernate-mapping>



的hibernate.cfg.xml

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
This template was written to work with NHibernate.Test.
Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
for your own use before compile tests in VisualStudio.
-->
<!-- This is the System.Data.dll provider for SQL Server -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string">
            Server=.;initial catalog=Lista6;Integrated Security=SSPI
        </property>
    <property name="adonet.batch_size">5</property>
        <property name="show_sql">true</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
        <property name="command_timeout">60</property>
        <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    <property name="generate_statistics">true</property>
    <mapping file="Child.hbm.xml" />
    <mapping file="Parent.hbm.xml" />
  </session-factory>
</hibernate-configuration>



你有什么想法,为什么批量大小不起作用?

Do you have any ideas why batch-size doesn't work?

推荐答案

您误解了批量大小表示。

这意味着它会读 5儿童的合集是在一次,而不是它会加载集合的5个元素。

It means it will read 5 COLLECTIONS OF Children at once, not that it will load 5 elements of the collection.

adonet.batch_size ,在另一方面,是指插入/更新/删除语句将在规模的团体,以较少的往返发送。

adonet.batch_size, on the other hand, means that insert/update/delete statements will be sent in groups of that size in order to have less roundtrips.

这篇关于NHibernate的批量大小不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 08:56