Thanks for your reply. That's right, they don't deliver duplicates within 
the *whole resultset*. That means the resultset itself is distinct. But 
when accessing single entities of the query one entity itself is not 
distinct, because the result is a cartesian product (left outer join) of 
all entities.
Think of an entity "category" with 10 rows and an entity "subcategory" with 
20 rows. 
The result of eager fetching both tables will contain 20 rows with all 
columns of both tables. When accessing entity "category" NHIbernate would 
return 20 rows instead of 10.

However for simple queries this seems to be working, but not for my case. 
I have an entity "list" which can have localized properties which are 
stored in "listlocales". A list can have one or many "articles". "articles" 
can also have "articlelocales". An article can only have one list. 
My query is

var query = session.Query<Lists>()
                   .FetchMany(x => x.Locales)        // list locales
                   .FetchMany(x => x.Articles)
                     .ThenFetchMany(x => x.Locales); // article locales

When accessing list locales the number of entries is the rowcount of all 
articles.

Maybe there is a problem that both properties are named "Locales". 
Otherwise it seems that NHibernate.Linq.ResultTransformer has to be patched 
...



Am Dienstag, 23. Oktober 2012 00:11:55 UTC+2 schrieb pete:
>
> I have the same problem as a user describes here: 
> http://groups.google.com/group/nhusers/browse_thread/thread/6a4c233931dc5eea 
>
> I just upgraded to NH 3.2.0GA where previously I was using NH2.2.4 with 
> Linq addin. One feature I had in my old repository was 
> SetResultTransformer(new DistinctRootEntityResultTransformer()) to ensure 
> unique records when I eagerly fetched values using left joins. My 
> Repository exposes IQueryable<T>. In NH 3 I am using Session.Query<T>, but 
> how can I add a ResultTransformer to that? 
>
> In NH2 with linq provider I could write 
>
>         var query = Session.Linq<T>().QueryOptions.RegisterCustomAction(x 
> => x.SetResultTransformer(new DistinctRootEntityResultTransformer())); 
>
> That always ensured that the Distinct Results were always applied. This 
> was useful when eagerly fetching a few collections at once (left joins) 
> which produced a Carteasian product. 
> How could that be done in NH3 with using IQueryable? I know that it could 
> be done with ICriteria but I want to use Linq. 
>
> Distinct is not working for this. 
>
> Thanks for your help. 

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/BixCGCrhe1wJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to