Hi,
How do I write a criteria query that retreives a single parent with a subset of the partent's children that have specific friends ?
For example,
Parents: Meg, Emily
Meg's Children: Sarah, Steve, Bo
Emily's Children: Marsha
Sarah's Friends : Tim, Jane
Steve's Friends : Tim
Bo's Friends : Alice
I would like to load Meg with only the children who have Tim as a friend.
In which case I would get Meg with only Sarah and Steve loaded.
So far my query is,
ICriteria ParentCrit = CurrentSession.CreateCriteria(typeof(Parent));
ICriteria ChildrenCrit = ParentCrit.CreateCriteria("Children");
ICriteria FriendsCrit = ChildrenCrit.CreateCriteria("Friend");
ParentCrit.Add(Expression.Eq("Id", "Meg"));
FriendsCrit.Add(Expression.In("Name", new object {"Tim"}))
.SetResultTransformer(CriteriaUtil.AliasToEntityMap);
When I call ParentCrit.List() I get a hash table with two identical Parent objects and their entire collection of children loaded. What do I need to change?
Thanks for reading.
Cheers,
Aeden
|