I am writing a query for a sortable grid using this QueryOver:
IQueryOver<Deal, Deal> query = session.QueryOver(() => _OrderAlias);
query.Left.JoinQueryOver(() => _OrderAlias.Employees, () =>
_OrderEmployeeAssigneeAlias,
() =>
_OrderEmployeeAssigneeAlias.OrderEmployeeType ==
OrderEmployeeType.Assignee);
query.Left.JoinQueryOver(() => _OrderAlias.Employees, () =>
_OrderEmployeeSalespersonAlias,
() =>
_OrderEmployeeSalespersonAlias.OrderEmployeeType ==
OrderEmployeeType.SalesPerson);
query.OrderBy(() => _OrderEmployeeSalespersonAlias.LastName).Desc;
Conditionally, the query will be built to sort by Assignee, not by
Salesperson, so this is the reason for the multiple joins to the same
table.
Running this query produces this exception:
NHibernate.QueryException: duplicate association path: Employees --->
System.ArgumentException: An item with the same key has already been
added.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue
value, Boolean add)
at NHibernate.Util.LinkedHashMap`2.Add(TKey key, TValue value)
at
NHibernate.Loader.Criteria.CriteriaQueryTranslator.CreateAssociationPathCriteriaMap()
I have seen posts about doing this with HQL, and a few that say this
is not currently supported in the Criteria API.
Is this correct? Is HQL the only way to join to a collection twice?
Can I do this using QueryOver? (Also, is there a better way to do
this than using two joins?)
Thanks in advance.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
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.