-2

我正在尝试为以下查询创建 Nhibernate 标准,但没有得到正确的想法。请指导

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 的子句创建标准。

4

1 回答 1

1

you need a correlated subquery

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"));
于 2012-05-14T12:54:59.303 回答