我有一个存储过程,我必须将其转换为Nhibernate创建查询。 Procedure有一个CASE子句。程序是:
Select * From tDRMaster
Where fDate =
Case When @Date IS NULL Then (Select Max(fDate) From tDRMaster Where fPropertyID = @PropertyID)
Else @Date
End
And fPropertyID = @PropertyID
答案 0 :(得分:1)
var results = session.CreateCriteria<DrMaster>()
.Add(Expression.EqProperty("fDate",
Projections.Conditional(Expression.Eq("Date", null),
Projections.SubQuery(DetachedCriteria.For<DrMaster>()
.Add(Expression.EqProperty("fPropertyId", "PropertyId"))
.SetProjection(Projections.Max("fDate"))),
Projections.Property("Date"))))
.Add(Expression.EqProperty("fPropertyId", "PropertyId"))
.List<DrMaster>();