Nhibernate: great results in the second level collection

I have an object model:

   class EntityA
   {
        ...
        IList<EntityB> BList;
        ...
   }

   class EntityB
   {
       ...
       IList<EntityC> CList;
   }

I need to get all the collections (Blist in EntityA and CList in EntityB), because if all of them are needed to perform some operations, if I will not load them, I will have the problem of choosing n + 1. Thus, the request was as follows:

  select a from EntityA a left join fetch a.BList b left join fetch b.CList c

, , - , EntityA, - BList. , , SQL, , , , SQL, , ( [] EntityA). :

  query.SetResultTransformer(new DistinctRootEntityResultTransformer());

. . , , EntityB - CList.

, ? , , ...

+3
3

, , . , C, . :

select a 
left join a.b b
left join b.c c

, db, :

1: a1 | b1 | c1
2: a1 | b1 | c2
3: a1 | b2 | c3
4: a1 | b2 | c4
...

(A) - C, DB B C. . HashSet, .

0

ISet IList ( , ).

.

0

I ran into the same problem and could not solve the duplication problem via hql. However, I created IEqualityComparer for all collections and made Disinct () in each collection to eliminate duplicates on top of the hql result.

0
source

Source: https://habr.com/ru/post/1731782/


All Articles