Model:
public class TestEntity : Entity
{
[Field, Key]
public Guid Id { get; set; }
[Field]
public decimal Sum { get; set; }
}
Test:
//OK
Assert.DoesNotThrow(() => Session.Current.Query.All<TestEntity>().Select(e => (Math.Truncate(Math.Round(e.Sum, 2) * 100) / 100)).ToArray());
//OK
Assert.DoesNotThrow(() => Session.Current.Query.All<TestEntity>().Where(e => (Math.Truncate(Math.Round(e.Sum, 2) * 100) / 100) > 1).ToArray());
//OK
Assert.DoesNotThrow(() => Session.Current.Query.All<TestEntity>().OrderBy(e => Math.Truncate(Math.Round(e.Sum, 2) * 100) / 100).ToArray());
//OK
Assert.DoesNotThrow(() => Session.Current.Query.All<TestEntity>().Sum(e => Math.Truncate(Math.Round(e.Sum, 2) * 100) / 100));
//OK
Assert.DoesNotThrow(() => Session.Current.Query.All<TestEntity>().Select(e => (Math.Truncate(Math.Round(e.Sum, 2, MidpointRounding.AwayFromZero) * 100) / 100)).ToArray());
//OK
Assert.DoesNotThrow(() => Session.Current.Query.All<TestEntity>().Where(e => (Math.Truncate(Math.Round(e.Sum, 2, MidpointRounding.AwayFromZero) * 100) / 100) > 1).ToArray());
//FAIL
Assert.DoesNotThrow(() => Session.Current.Query.All<TestEntity>().OrderBy(e => Math.Truncate(Math.Round(e.Sum, 2, MidpointRounding.AwayFromZero) * 100) / 100).ToArray());
//FAIL
Assert.DoesNotThrow(() => Session.Current.Query.All<TestEntity>().Sum(e => Math.Truncate(Math.Round(e.Sum, 2, MidpointRounding.AwayFromZero) * 100) / 100));
Exception:
(Unable to translate 'Query.All().OrderBy(e => (Math.Truncate((Math.Round(
e.Sum,
2,
$<MidpointRounding>(AwayFromZero)
) * $<Decimal>(100))) / $<Decimal>(100)))' expression. See inner exception for details.)
at Xtensive.Orm.Linq.QueryProvider.Translate[TResult](Expression expression, CompilerConfiguration compilerConfiguration)
at Xtensive.Orm.Linq.QueryProvider.Execute[TResult](Expression expression)
at Xtensive.Orm.Linq.Queryable`1.GetEnumerator()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
Expression of type 'System.Int32' cannot be used for parameter of type 'System.MidpointRounding' of method 'System.Decimal Round(System.Decimal, Int32, System.MidpointRounding)'
at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ReadOnlyCollection`1& arguments)
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Linq.ExpressionVisitor.VisitBinary(BinaryExpression b)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Linq.ExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 expressions)
at Xtensive.Linq.ExpressionVisitor.VisitMethodCall(MethodCallExpression mc)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Linq.ExpressionVisitor.VisitBinary(BinaryExpression b)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Orm.Linq.Translator.CreateCalculatedColumnDescriptor(LambdaExpression expression)
at Xtensive.Orm.Linq.Translator.ProcessProjectionElement(Expression body)
at Xtensive.Orm.Linq.Translator.VisitLambda(LambdaExpression le)
at Xtensive.Orm.Linq.Translator.VisitSort(Expression expression)
at Xtensive.Orm.Linq.Translator.VisitQueryableMethod(MethodCallExpression mc, QueryableMethodKind methodKind)
at Xtensive.Linq.QueryableVisitor.VisitMethodCall(MethodCallExpression mc)
at Xtensive.Orm.Linq.Translator.VisitMethodCall(MethodCallExpression mc)
at Xtensive.Linq.ExpressionVisitor`1.Visit(Expression e)
at Xtensive.Orm.Linq.Translator.Translate[TResult]()
at Xtensive.Orm.Linq.QueryProvider.Translate[TResult](Expression expression, CompilerConfiguration compilerConfiguration)
DO 5.0.7
asked
Oct 11 '16 at 05:37
Anton Guschin
73●30●30●35
DO 5.0.10, same exception