Nhibernate DetachedCriteria Left Outer Join on subquery
-
20-09-2019 - |
Question
I'll only try to present the main part of the problem, because the whole situation is much more complicated - I am unable to achieve the following with DetachedCriteria
SELECT *
FROM User
LEFT OUTER JOIN GroupItem
ON User.ID = GroupItem.UserID
AND _groupItemRestrictions_
There can be multiple GroupDefinitions, User can belong to multiple GroupItems which each belong to it's own GroupDefinition. Due to some complicated reason with paging/sorting and (multilevel) group behavior, I cannot achieve appropriate paging behavior with this query:
SELECT *
FROM User
LEFT OUTER JOIN GroupItem
ON User.ID = GroupItem.UserID
WHERE _groupItemRestrictions_
A query similar to the second one is produced this way:
var criteria = DetachedCriteria.For<User>()
...
GroupItem groupItem = null;
criteria.CreateAlias(() => groupItemAlias, () => groupItem,
JoinType.LeftOuterJoin);
criteria.Add(Restrictions.Or(...));
...
Is it possible to create the first query with DetachedCriteria?
Thanks!
Solution
Seems that there is no way to specify such a query with DetachedCriteria yet, but there is with HQL using a 'with' clause:
http://fabiomaulo.blogspot.com/2009/05/nhibernate-210-hql-with-clause.html
http://www.mail-archive.com/nhusers@googlegroups.com/msg08451.html
UPDATE:
https://nhibernate.jira.com/browse/NH-1946
The feature has been implemented now. Thanks to NH team :)