Search code examples
vb.netnhibernatenhibernate-criteria

Nhibernate partial eager load of child collection


If I have a parent object (Parent) which has a List(Of Child) objects as a many-one relationship. Is it possible to return a Parent with a subset of it's child objects (eagerly loaded)? I am using VB and Criteria.

e.g. If Parent 1 has 50 children (20 type X 30 type Y) and I want to return the Parent with a collection containing only type X.

I only want a collection with a size of 20 with it's eagerly loaded children?

Thanks


Solution

  • HQL query. The fetch keyword will initialize the children along with the parent.

    from parent left join fetch parent.Children as child where child.type = X