NHibernate returning duplicate object in child collections when using Fetch

后端 未结 5 1858
轮回少年
轮回少年 2021-02-19 01:35

When doing a query like this (using Nhibernate 2.1.2):

 ICriteria criteria = session.CreateCriteria()
                .SetFetchMode(\"ChildColl         


        
5条回答
  •  后悔当初
    2021-02-19 02:25

    Try using Futures:

    ICriteria criteriaFuture1
        = session.CreateCriteria()
            .SetFetchMode("ChildCollection1", FetchMode.Eager)
            .Add(Restrictions.IdEq(id))
            .SetResultTransformer(Transformers.DistinctRootEntity)
            .FutureValue();
     ICriteria criteriaFuture2
        = session.CreateCriteria()
            .SetFetchMode("ChildCollection2", FetchMode.Eager)
            .Add(Restrictions.IdEq(id))
            .SetResultTransformer(Transformers.DistinctRootEntity)
            .FutureValue();
    
     return criteriaFuture1.Value;
    

提交回复
热议问题