I have found this article (
http://ayende.com/blog/4151/nhibernate-tips-tricks-efficiently-selecting-a-tree)
 
and it works if I get all the people, but if I try to filter the children 
and get only the people in a department, nhibernate send a query to the 
database each time that I access the Children collection of the Person.
 
This works:
session.CreateQuery("SELECT p FROM Person p LEFT JOIN FETCH p.Children")
 .SetResultTransformer(new DistinctRootEntityResultTransformer())
 .List<Person>();
 
 
This works too, but accessing the Children collection trigger a select to 
the database to get all the children.
session.CreateQuery("SELECT p FROM Person p LEFT JOIN FETCH p.Children c 
LEFT JOIN c.Departments d WHERE d.Id In (:ids)")
 .SetParameterList("ids", new Guid[] { 
Guid.Parse("2C28E6E0-1C3A-429F-A2C6-3CD83854E6D3") }.ToList())
 .SetResultTransformer(new DistinctRootEntityResultTransformer())
 .List<Person>();
 

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/NwYD7dukzLQJ.
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