我要在NHibernate QueryOver中生成以下查询。
SELECT E.EmployeeName
FROM Employees E
INNER JOIN Department D
ON E.EmployeeId = E.EmployeeId
INNER JOIN Qualifications Q
ON E.EmployeeId = Q.EmployeeId
WHERE D.DepartmentKey IN(1,2)
AND Q.QualificationKey IN (3,4)
GROUP BY EmployeeName
HAVING count(distinct STR(D.DepartmentKey) + STR(Q.QualificationKey)) = 2*2
我正在尝试应用具有SQL功能模板的Count Distinct的Having条件。
这是我对计数不同的代码: -
query.Where(Restrictions.Eq
(Projections.CountDistinct<Employee>(c =>
Projections.SqlFunction( new SQLFunctionTemplate (NHibernateUtil.String,
"STR(?1) + STR(?2)"),
NHibernateUtil.String,
Projections.ProjectionList().
Add(Projections.Property(() => DepartmentAlias.DepartmentKey)).
Add(Projections.Property(() => QualificationAlias.QualificationKey)))),
departmentSelectionCount * qualificationSelectionCount))
我收到以下错误: -
{"Unrecognised method call in expression SqlFunction
(new SQLFunctionTemplate(NHibernateUtil.String, \"STR(?1) + STR(?2)\"),
NHibernateUtil.String, new [] {ProjectionList().
Add(Property(() => value(DepartmentAlias.DepartmentKey)).
Add(Property(() => value(QualificationAlias.QualificationKey))})"}
对此有任何帮助将非常感谢!!
先谢谢!!