提交 d5eed857 编写于 作者: S Shay Rojansky

Fix Math.Round/Truncate over decimal

Fixes #2379

(cherry picked from commit be5576bc)
上级 3676d3cc
...@@ -195,13 +195,15 @@ public class NpgsqlMathTranslator : IMethodCallTranslator ...@@ -195,13 +195,15 @@ public class NpgsqlMathTranslator : IMethodCallTranslator
if (TruncateMethodInfos.Contains(method)) if (TruncateMethodInfos.Contains(method))
{ {
var argument = arguments[0]; var argument = arguments[0];
// Result of trunc for float/double is always double in server side
// C# has Round over decimal/double/float only so our argument will be one of those types (compiler puts convert node)
// In database result will be same type except for float which returns double which we need to cast back to float.
var result = (SqlExpression)_sqlExpressionFactory.Function( var result = (SqlExpression)_sqlExpressionFactory.Function(
"trunc", "trunc",
new[] { argument }, new[] { argument },
nullable: true, nullable: true,
argumentsPropagateNullability: new[] { true, false, false }, argumentsPropagateNullability: new[] { true, false, false },
typeof(double)); argument.Type == typeof(float) ? typeof(double) : argument.Type);
if (argument.Type == typeof(float)) if (argument.Type == typeof(float))
{ {
...@@ -214,13 +216,15 @@ public class NpgsqlMathTranslator : IMethodCallTranslator ...@@ -214,13 +216,15 @@ public class NpgsqlMathTranslator : IMethodCallTranslator
if (RoundMethodInfos.Contains(method)) if (RoundMethodInfos.Contains(method))
{ {
var argument = arguments[0]; var argument = arguments[0];
// Result of round for float/double is always double in server side
// C# has Round over decimal/double/float only so our argument will be one of those types (compiler puts convert node)
// In database result will be same type except for float which returns double which we need to cast back to float.
var result = (SqlExpression) _sqlExpressionFactory.Function( var result = (SqlExpression) _sqlExpressionFactory.Function(
"round", "round",
new[] { argument }, new[] { argument },
nullable: true, nullable: true,
argumentsPropagateNullability: new[] { true, true }, argumentsPropagateNullability: new[] { true, true },
typeof(double)); argument.Type == typeof(float) ? typeof(double) : argument.Type);
if (argument.Type == typeof(float)) if (argument.Type == typeof(float))
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册