C# 在投影中添加多个条件。queryover的条件
我试图用一个以上的C# 在投影中添加多个条件。queryover的条件,c#,nhibernate,conditional-statements,queryover,C#,Nhibernate,Conditional Statements,Queryover,我试图用一个以上的when子句编写一个案例;大概是这样的: ... case when 'starks' then 1 when 'wildlings' then 2 when 'lannisters' then 3 Else 0 End ... 我以前做过一个条件测试,比如 .OrderBy(Projections.Conditional( Restrictions.Where<House>(r => r.Name.IsLike("s
when
子句编写一个案例;大概是这样的:
...
case
when 'starks' then 1
when 'wildlings' then 2
when 'lannisters' then 3
Else 0
End
...
我以前做过一个条件测试,比如
.OrderBy(Projections.Conditional(
Restrictions.Where<House>(r => r.Name.IsLike("starks")),
Projections.Constant(0),
Projections.Constant(1))).Asc();
.OrderBy(Projections.Conditional)(
限制。其中(r=>r.Name.IsLike(“starks”),
投影。常数(0),
常量(1)).Asc();
但我不知道如何在其中添加一个额外的条件/子句:/
我尝试添加额外的外部条件、额外限制等,但最终总是出现语法错误
感谢您的帮助。投影。有条件的
返回i投影
,其签名为:
/// <summary>
/// Conditionally return the true or false part, dependention on the criterion
/// </summary>
/// <param name="criterion">The criterion.</param><param name="whenTrue">The when true.
/// </param><param name="whenFalse">The when false.</param>
/// <returns/>
public static IProjection Conditional(ICriterion criterion
, IProjection whenTrue
, IProjection whenFalse);
太好了,也谢谢你的解释,教我如何钓鱼,真的。很高兴看到这一点;)享受NHiberante,很棒的工具;)我们如何使用多个限制条件,例如当(gl.parent为null且gltype!=“parent”)时的Case,然后当(gl.parent为not null且po.amount<1000)时的'I'Case,然后是'X'
.OrderBy
(
Projections.Conditional(
Restrictions.Where<House>(r => r.Name.IsLike("starks")),
Projections.Constant(1),
Projections.Conditional(
Restrictions.Where<House>(r => r.Name.IsLike("wildlings")),
Projections.Constant(2),
Projections.Conditional(
Restrictions.Where<House>(r => r.Name.IsLike("lannisters")),
Projections.Constant(3),
Projections.Constant(0)
)
)
)
)
.Asc()
ORDER BY
(case when this_.Name LIKE 'starks' then 1 else
(case when this_.Name LIKE 'wildlings' then 2 else
(case when this_.Name LIKE 'lannisters' then 3 else 0 end) end) end) asc