本文整理汇总了C#中NHibernate.Hql.Ast.HqlTreeBuilder.Constant方法的典型用法代码示例。如果您正苦于以下问题:C# HqlTreeBuilder.Constant方法的具体用法?C# HqlTreeBuilder.Constant怎么用?C# HqlTreeBuilder.Constant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Hql.Ast.HqlTreeBuilder
的用法示例。
在下文中一共展示了HqlTreeBuilder.Constant方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildHql
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
return treeBuilder.Like(
visitor.Visit(targetObject).AsExpression(),
treeBuilder.Concat(
treeBuilder.Constant("%"),
visitor.Visit(arguments[0]).AsExpression(),
treeBuilder.Constant("%")));
}
示例2: BuildHql
public override HqlTreeNode BuildHql(
MethodInfo method,
Expression targetObject,
ReadOnlyCollection<Expression> arguments,
HqlTreeBuilder treeBuilder,
IHqlExpressionVisitor visitor)
{
var left = treeBuilder.Cast(visitor.Visit(targetObject).AsExpression(), typeof(string));
var right = treeBuilder.Cast(visitor.Visit(arguments.First()).AsExpression(), typeof(string));
var leftSubstring = treeBuilder.MethodCall("substring", left, treeBuilder.Constant(4));
var rightSubstring = treeBuilder.MethodCall("substring", right, treeBuilder.Constant(4));
var equals = treeBuilder.Equality(leftSubstring, rightSubstring);
return equals;
}
开发者ID:nhibernate,项目名称:nhibernate-core,代码行数:15,代码来源:EntityWithUserTypePropertyIsEquivalentGenerator.cs
示例3: GetRhs
private static HqlExpression GetRhs(MethodInfo method, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
if (arguments.Count > 0)
return visitor.Visit(arguments[0]).AsExpression();
var returnType = method.ReturnType;
var instance = returnType.IsValueType ? Activator.CreateInstance(returnType) : null;
return treeBuilder.Constant(instance);
}
示例4: 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));
}
示例5: BuildHql
public HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments,
HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
if (arguments.Count == 2)
{
return treeBuilder.Like(
visitor.Visit(arguments[0]).AsExpression(),
visitor.Visit(arguments[1]).AsExpression());
}
if (arguments[2].NodeType == ExpressionType.Constant)
{
var escapeCharExpression = (ConstantExpression)arguments[2];
return treeBuilder.Like(
visitor.Visit(arguments[0]).AsExpression(),
visitor.Visit(arguments[1]).AsExpression(),
treeBuilder.Constant(escapeCharExpression.Value));
}
throw new ArgumentException("The escape character must be specified as literal value or a string variable");
}
示例6: BuildHql
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
if (arguments.Count == 1)
{
return treeBuilder.MethodCall("locate",
visitor.Visit(arguments[0]).AsExpression(),
visitor.Visit(targetObject).AsExpression(),
treeBuilder.Constant(0));
}
return treeBuilder.MethodCall("locate",
visitor.Visit(arguments[0]).AsExpression(),
visitor.Visit(targetObject).AsExpression(),
visitor.Visit(arguments[1]).AsExpression());
}
示例7: BuildHql
///<summary>
///
///</summary>
///<param name="method"></param>
///<param name="targetObject">Should be an ISecurable</param>
///<param name="arguments">Not sure what the heck arg[0] is, but arg[1] is the entityName</param>
///<param name="treeBuilder"></param>
///<param name="visitor"></param>
///<returns></returns>
public override HqlTreeNode BuildHql(
MethodInfo method,
Expression targetObject,
ReadOnlyCollection<Expression> arguments,
HqlTreeBuilder treeBuilder,
IHqlExpressionVisitor visitor)
{
// arguments[0] is a System.Linq.Expressions.Expression
// arguments[1] is our constant value
var expr = arguments[0];
// This doesn't really help us right now, but log it just in case...
if (expr is Remotion.Linq.Clauses.Expressions.QuerySourceReferenceExpression)
{
Console.WriteLine(
"ReferencedQuerySource: {0}",
((Remotion.Linq.Clauses.Expressions.QuerySourceReferenceExpression)expr).ReferencedQuerySource
);
}
// Getting somewhere?
// expr.Type is Spc.Ofp.Tubs.DAL.Entities.Trip
Console.WriteLine("Expression type: {0}", expr.Type);
// HqlAlias is "AccessControl" (entity property), "ace" (name used in expression) ?
// HqlExpression is equality expression ?
var aceAlias = treeBuilder.Alias("AccessControl as ace");
var entityName = ((ConstantExpression)arguments[1]).Value;
Console.WriteLine("entityName: {0}", entityName);
var equality = treeBuilder.Equality(
treeBuilder.Alias("ace.EntityName"),
treeBuilder.Constant(entityName)
);
var joinExpression = treeBuilder.Join(equality, aceAlias);
// This doesn't actually do anything...
return visitor.Visit(expr).AsExpression();
/*
* var dc =
DetachedCriteria.For<T>()
.CreateAlias("AccessControl", "ace", JoinType.InnerJoin)
.Add(NHibernate.Criterion.Expression.Eq("ace.EntityName", this._entityName));
*/
}
示例8: BuildFromArray
private HqlTreeNode BuildFromArray(Array valueArray, HqlTreeBuilder treeBuilder)
{
var elementType = valueArray.GetType().GetElementType();
if (!elementType.IsValueType && elementType != typeof(string))
throw new ArgumentException("Only primitives and strings can be used");
Type enumUnderlyingType = elementType.IsEnum ?
Enum.GetUnderlyingType(elementType) : null;
var variants = new HqlExpression[valueArray.Length];
for (int index = 0; index < valueArray.Length; index++)
{
var variant = valueArray.GetValue(index);
var val = variant;
if (elementType.IsEnum)
val = Convert.ChangeType(variant, enumUnderlyingType);
variants[index] = treeBuilder.Constant(val);
}
return treeBuilder.DistinctHolder(variants);
}
示例9: BuildHql
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
var length = arguments.Count == 1
? treeBuilder.Subtract(treeBuilder.MethodCall("length", visitor.Visit(targetObject).AsExpression()), visitor.Visit(arguments[0]).AsExpression())
: visitor.Visit(arguments[1]).AsExpression();
return treeBuilder.MethodCall("substring", visitor.Visit(targetObject).AsExpression(),
treeBuilder.Add(visitor.Visit(arguments[0]).AsExpression(), treeBuilder.Constant(1)),
length);
}
示例10: BuildHql
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
return treeBuilder.Constant(1);
}
示例11: BuildFromArray
private HqlTreeNode BuildFromArray(IEnumerable valueArray, HqlTreeBuilder treeBuilder, Type elementType)
{
Type enumUnderlyingType = elementType.IsEnum ? Enum.GetUnderlyingType(elementType) : null;
IList<HqlTreeNode> variants = new List<HqlTreeNode>();
foreach (object variant in valueArray)
{
object val = variant;
if (elementType.IsEnum)
val = Convert.ChangeType(variant, enumUnderlyingType);
HqlConstant hqlConstant = treeBuilder.Constant(val);
variants.Add(hqlConstant);
}
return treeBuilder.ExpressionSubTreeHolder(variants);
}