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%20Guschin's gravatar image

Anton Guschin
73223035

DO 5.0.10, same exception

(Oct 11 '16 at 06:24) Anton Guschin Anton%20Guschin's gravatar image

One Answer:

Hello Anton

This is known problem. As I remember the solution was planned for 5.0.11 Final. There are another cases connected with enum to int(long) conversions. I will add this case to already known cases.

answered Dec 05 '16 at 04:07

Alexey%20Kulakov's gravatar image

Alexey Kulakov
45215

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA