Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Linq - fixed substring function

  • Loading branch information...
commit e848338e6fd6cd1ae9a6b9ef591228f78d7257d1 1 parent bae8e09
@hazzik hazzik authored
Showing with 5 additions and 8 deletions.
  1. +5 −8 src/NHibernate/Linq/Functions/StringGenerator.cs
View
13 src/NHibernate/Linq/Functions/StringGenerator.cs
@@ -119,16 +119,13 @@ public SubStringGenerator()
}
public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
- if (arguments.Count == 1)
- {
- return treeBuilder.MethodCall("substring", visitor.Visit(targetObject).AsExpression(),
- treeBuilder.Constant(0),
- visitor.Visit(arguments[0]).AsExpression());
- }
+ 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(),
- visitor.Visit(arguments[0]).AsExpression(),
- visitor.Visit(arguments[1]).AsExpression());
+ treeBuilder.Add(visitor.Visit(arguments[0]).AsExpression(), treeBuilder.Constant(1)),
+ length);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.