views:

289

answers:

0

When querying into child collections should I be wary of performance and duplicate results which result from the use of CreateAlias("ChildCollectionName", "alias")

would you think it would be better to just perform subqueries on Child Collections to get a big list of "parentId"s and then do an In clause on the parent.

For Example

class Parent
{
    List<ChildOne> ChildrenOne
    List<ChildTwo> ChildrenTwo
    ParentNestedObject NestedObject
}

class ChildOne{
    public string PropertyOne
}

class ChildTwo{
   public string PropertyTwo
}

And my criteria requires such things as ... find all Parent for NestedObject matches criteria OR, ChildrenOne contains any ChildOne matching a criteria OR, (the same list criteria for ChildrenTwo)

What I'm finding is that when using CreateAlias("ChildrenOne", "co", LeftOuterJoin) that i'm getting duplicate rows back.

I know that ResultTransformers are considered bad practice because they operate on the set after it is returned from the DB.

Is a better alternative in this case... "Select all ChildOne for criteria, set projection ChildOne.ParentId, then do "Find all parent where ParentId in (this list of ids, that list of ids, another list of ids)

It would seem that I would get better "DISTINCT" results in the end from that approach rather than trying to use CreateAlias or CreateCriteria

Fairly recently this fellow was told that criteria on a child collection wasn't something that could be done (unless I interpret that incorrectly) however, I seem to be able to get success using CreateAlias albeit with duplicate result rows.

I would love to hear any opinions on the above.

related questions