views:

355

answers:

0

Hi I have this multi-criteria, which works very well, except that I'm getting multiple of the same entities in the collections. I know this is by design, and I know you should be able to use a ResultTransformer to avoid it or filtering through a hashed set after quering.

My query looks like this:

IMultiCriteria criteria = session.CreateMultiCriteria()
    .Add(DetachedCriteria.For<Building>()
    .Add(Restrictions.Eq("Id", BuildingId))
    .CreateCriteria("Windows", JoinType.LeftOuterJoin)
        .SetFetchMode("Shadows", FetchMode.Eager))
    .Add(DetachedCriteria.For<Building>()
    .Add(Restrictions.Eq("Id", BuildingId))
        .CreateCriteria("BuildingParts", JoinType.LeftOuterJoin)
        .CreateCriteria("Windows", JoinType.LeftOuterJoin))

The HashedSet filtering solution is not possible for me, as I cannot set the collection back on the entity - they have a private setter.

I have tried the ResultTransformer with DistinctRootEntityResultTransformer, but I can't get it to work. It keeps returning multiple of the same entities in the collections BuildingParts and Windows.

Any suggestions of what to do? Or how to get the ResultTransformer to work?