简体   繁体   中英

NHibernate Lazy Loading = false

I set lazy="false" to a collection and fetch="select" , but I dont understand why NHibernate keeps loading my collection.

This is my mapping:

 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="Ortopedia.Entidades" assembly="Ortopedia">
  <class name="Especialidade" table="TB_ESPECIALIDADE">
    <id name="Id">
      <column name="ID_ESPECIALIDADE" not-null="true" />
      <generator class="increment" />
    </id>
    <property name="Nome" column="NOME" not-null="true" length="50" />
    <set inverse="true" name="SubEspecialidades" cascade="none" fetch="select" lazy="false" >
      <key column="ID_ESPECIALIDADE" />
      <one-to-many class="Ortopedia.Entidades.SubEspecialidade" />
    </set>
  </class>
</hibernate-mapping>

And this is the code I'm using to list the data:

ICriteria criteria = session.CreateCriteria(typeof(T));
criteria.SetMaxResults(1000);
IList<T> list = criteria.List<T>();
return list;

NHibernate loads my SubEspecialidades property, I dont want it to load. What am I missing here?

If you don't want SubEspecialidades to load initially, you should be using:

lazy="true"

Lazy loading means that the collection will not be fetched from the database until you access it in your code. So if you set it to false, it will be fetched along with its parent object (whatever owns the collection).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM