I am trying to reproduce a query using the Nhibernate APIs and cannot decide how to add a criteria clause, which allows me to compare two values from different tables.
The best trivial example I could come up with ....
SELECT e.LastName
FROM Employee e
JOIN Chair c ON c.ChairId = e.ChairId
WHERE e.Weight > c.MaxLoad
My main Nhibernate criteria
ICriteria criteria = base.Session.CreateCriteria(typeof(Employee));
criteria.CreateAlias("Employee.Chairid", "Chair", JoinType.InnerJoin);
One overload of the creation alias has an additional parameter withClause, which seems to be the proposed way to achieve this, but for my life I cannot find an example of the syntax I need to achieve this.
I think I need something like ...
criteria.Add(Expression.Ge("Employee.Weight", "Chair.MaxLoad"));
but this obviously does not work, as the second parameter will be treated as a string value.
Any help was appreciated.
source
share