|
Hi,
I have 2 levels of collections of objects: Network has collection of Device, and Device has collection of Resource.
In the Device.hbm.xml file I specify that Resources (its collection of Resource) has property lazy = true.
In my NHibernate provider I write this method:
(T is for Network)
public IList<T> LoadAllInSeparatedSession(String associationPathLevel1, String associationPathLevel2)
{
ISession separatedSession = NHibernateHelper.GetSeparatedSession();
DetachedCriteria query;
if (!String.IsNullOrEmpty(associationPathLevel2))
{
query = DetachedCriteria.For(typeof (T))
.SetFetchMode(associationPathLevel1, FetchMode.Join)
.SetFetchMode(associationPathLevel1 + "." + associationPathLevel2, FetchMode.Join)
.SetResultTransformer(new DistinctRootEntityResultTransformer());
}
else
{
query = DetachedCriteria.For(typeof (T))
.SetFetchMode(associationPathLevel1, FetchMode.Join)
.SetResultTransformer(new DistinctRootEntityResultTransformer()); // Evita record duplicati
}
IList<T> results = query.GetExecutableCriteria (separatedSession).List<T>();
NHibernateHelper.CloseSeparatedSession(separatedSession);
return results;
}
I realized that the "DistinctRootEntityResultTransformer" is applied only to the first level (root) Network.
How is it possible to apply DistinctRootEntityResultTransformer to the second level too ?
Thank's
bye Andrea
|