0

我有一个存储过程,我必须将其转换为 Nhibernate 创建查询。过程有一个 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 
4

1 回答 1

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>();
于 2013-06-11T05:29:11.030 回答