I'm trying to fetch a collection of root entities with *some *of their
children. I then need to iterate these to create a dto to send to client,
I.e. the client wants all entities that have changed so it can update a
local database.

The problem is when I try to iterate the child collection NH tries to lazy
load the entire collection rather than just iterating through what it has.

E.g.

var customers = session.CreateCriteria<Customer>()
    .CreateAlias("Orders", "order")
    .Add(Restrictions.Gt("o.LastModified", lastModifiedDate)
    .List();

foreach(var customer in customers)
    foreach(var order in customer)
        // triggers lazy load of all orders for this customer


How can I ensure I only loop through the filtered collection? The only
alternative is to grab the child collection by itself and send that but this
is a complex object graph which will mean I end up having to send lots of
collections, it seemed much cleaner to send the root entity with the
relevant collections filtered.

Surely I'm missing something obvious here?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to