我正在尝试为以下查询创建Nhibernate标准,但没有得到正确的想法。 Plz指南
SELECT PEH.ResponseStatus FROM PatientEligibilityHistory PEH WHERE PEH.PatientId = " + patientId + " AND PEH.PayorId = " + payorId + " AND PEH.DateOfService = '" + dateOfService + "' AND PEH.Insured_Id = '" + insuredId + "' HAVING PEH.ResponseDateTime = MAX(PEH.ResponseDateTime)
我无法理解如何使用max。
为子句创建条件答案 0 :(得分:1)
你需要一个相关的子查询
DetachedCriteria query = DetachedCriteria.For<PatientEligibilityHistory>()
.Add(Expression.In("PatientId", patientList))
.Add(Expression.In("PatientCaseId", patientCaseList))
.Add(Expression.In("PayorId", payorList))
.Add(Expression.In("InsuredId", insuredList));
DetachedCriteria subquery = CriteriaTransformer.Clone(query).SetProjection(Projections.Max("ResponseDateTime"));
ICriteria criteria = query.GetExecutableCriteria(session)
.Add(Subquery.Eq("ResponseDateTime", subquery));
.SetProjection(Projections.Max("ResponseStatus"));