本文整理汇总了C#中NHibernate.Hql.Ast.HqlTreeBuilder.When方法的典型用法代码示例。如果您正苦于以下问题:C# HqlTreeBuilder.When方法的具体用法?C# HqlTreeBuilder.When怎么用?C# HqlTreeBuilder.When使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Hql.Ast.HqlTreeBuilder
的用法示例。
在下文中一共展示了HqlTreeBuilder.When方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertBooleanToCase
public static HqlExpression ConvertBooleanToCase(HqlExpression node)
{
if (node is HqlBooleanExpression)
{
var builder = new HqlTreeBuilder();
return builder.Case(
new[] {builder.When(node, builder.True())},
builder.False());
}
return node;
}
示例2: BuildHql
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
// Instance CompareTo() or static string.Compare()?
Expression lhs = arguments.Count == 1 ? targetObject : arguments[0];
Expression rhs = arguments.Count == 1 ? arguments[0] : arguments[1];
HqlExpression lhs1 = visitor.Visit(lhs).AsExpression();
HqlExpression rhs1 = visitor.Visit(rhs).AsExpression();
HqlExpression lhs2 = visitor.Visit(lhs).AsExpression();
HqlExpression rhs2 = visitor.Visit(rhs).AsExpression();
// CASE WHEN (table.[Name] = N'Foo') THEN 0
// WHEN (table.[Name] > N'Foo') THEN 1
// ELSE -1 END
return treeBuilder.Case(
new[]
{
treeBuilder.When(treeBuilder.Equality(lhs1, rhs1), treeBuilder.Constant(0)),
treeBuilder.When(treeBuilder.GreaterThan(lhs2, rhs2), treeBuilder.Constant(1))
},
treeBuilder.Constant(-1));
}