Lazy Download at NHibernate

If the Client has many Orders attached to them. How would you be lazy to load a list of orders using NHibernate.

Is this something you need to set up a mapping file? any help or example would be great.

+3
source share
5 answers

Here is a good article:

http://blogs.chayachronicles.com/sonofnun/archive/2007/03/30/230.aspx

From the above article:

The most common is simply to mark the class with the attribute 'lazy = "true" or put' default-lazy = "true" in the mapping declaration:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="@core.assembly@"
 default-access="nosetter.camelcase-underscore" default-lazy="true">

or

<class name="Cei.eMerge.Core.Domain.Contacts.Contact" table="Contact" lazy="true" >
+4
source

- , , , , Fetchmode :

criteria.SetFetchMode("Orders", FetchMode.Lazy)
+7

, "lazy = true" . :

<bag name="EmploymentHistory" cascade="all" inverse="true" lazy="true">
  <key column="PersonID" />
  <one-to-many class="MyDomain.EmploymentRecord, MyDomainAssembly" />
</bag>
+2

, , , .

Customer customer = session.CreateCriteria(...)
              .SetFetchMode("Orders", FetchMode.Lazy)
              .UniqueResult<Customer>();

Ilist<Order> orders = session.CreateFilter(customer.Orders," WHERE this.OrderDate < ?")
                      .SetDateTime(...).List();
+1

, Customer , ? , .
, , :
?

, ? , Customer.
, :

IList<Order> GetOrdersForCustomer( Customer c );

, .

+1

Source: https://habr.com/ru/post/1704865/


All Articles