Skip to content

Commit 3d1d8d6

Browse files
committed
Math.Truncate rounds towards 0. Use FIX instead of INT to match that behaviour
1 parent f72fd5f commit 3d1d8d6

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetMathTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public class JetMathTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMe
226226
resultType = typeof(double);
227227
}
228228
var result = (SqlExpression)_sqlExpressionFactory.Function(
229-
"INT",
229+
"FIX",
230230
[argument],
231231
nullable: true,
232232
argumentsPropagateNullability: [true],

test/EFCore.Jet.FunctionalTests/Query/NorthwindFunctionsQueryJetTest.Functions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ public override async Task Sum_over_truncate_works_correctly_in_projection(bool
11681168
AssertSql(
11691169
"""
11701170
SELECT `o`.`OrderID`, (
1171-
SELECT IIF(SUM(INT(`o0`.`UnitPrice`)) IS NULL, 0.0, SUM(INT(`o0`.`UnitPrice`)))
1171+
SELECT IIF(SUM(FIX(`o0`.`UnitPrice`)) IS NULL, 0.0, SUM(FIX(`o0`.`UnitPrice`)))
11721172
FROM `Order Details` AS `o0`
11731173
WHERE `o`.`OrderID` = `o0`.`OrderID`) AS `Sum`
11741174
FROM `Orders` AS `o`
@@ -1183,7 +1183,7 @@ public override async Task Sum_over_truncate_works_correctly_in_projection_2(boo
11831183
AssertSql(
11841184
"""
11851185
SELECT `o`.`OrderID`, (
1186-
SELECT IIF(SUM(INT(`o0`.`UnitPrice` * `o0`.`UnitPrice`)) IS NULL, 0.0, SUM(INT(`o0`.`UnitPrice` * `o0`.`UnitPrice`)))
1186+
SELECT IIF(SUM(FIX(`o0`.`UnitPrice` * `o0`.`UnitPrice`)) IS NULL, 0.0, SUM(FIX(`o0`.`UnitPrice` * `o0`.`UnitPrice`)))
11871187
FROM `Order Details` AS `o0`
11881188
WHERE `o`.`OrderID` = `o0`.`OrderID`) AS `Sum`
11891189
FROM `Orders` AS `o`
@@ -1209,7 +1209,7 @@ public override async Task Select_math_truncate_int(bool isAsync)
12091209

12101210
AssertSql(
12111211
$"""
1212-
SELECT INT(CDBL(`o`.`OrderID`)) AS `A`
1212+
SELECT FIX(CDBL(`o`.`OrderID`)) AS `A`
12131213
FROM `Orders` AS `o`
12141214
WHERE `o`.`OrderID` < 10250
12151215
""");
@@ -1235,7 +1235,7 @@ public override async Task Where_math_truncate(bool isAsync)
12351235
$"""
12361236
SELECT `o`.`OrderID`, `o`.`ProductID`, `o`.`Discount`, `o`.`Quantity`, `o`.`UnitPrice`
12371237
FROM `Order Details` AS `o`
1238-
WHERE `o`.`Quantity` < 5 AND INT(`o`.`UnitPrice`) > 10.0
1238+
WHERE `o`.`Quantity` < 5 AND FIX(`o`.`UnitPrice`) > 10.0
12391239
""");
12401240
}
12411241

@@ -1597,7 +1597,7 @@ public override async Task Where_mathf_truncate(bool async)
15971597
"""
15981598
SELECT `o`.`OrderID`, `o`.`ProductID`, `o`.`Discount`, `o`.`Quantity`, `o`.`UnitPrice`
15991599
FROM `Order Details` AS `o`
1600-
WHERE `o`.`Quantity` < 5 AND IIF(INT(CSNG(`o`.`UnitPrice`)) IS NULL, NULL, CSNG(INT(CSNG(`o`.`UnitPrice`)))) > 10
1600+
WHERE `o`.`Quantity` < 5 AND IIF(FIX(CSNG(`o`.`UnitPrice`)) IS NULL, NULL, CSNG(FIX(CSNG(`o`.`UnitPrice`)))) > 10
16011601
""");
16021602
}
16031603

@@ -1607,7 +1607,7 @@ public override async Task Select_mathf_truncate(bool async)
16071607

16081608
AssertSql(
16091609
"""
1610-
SELECT IIF(INT(CSNG(`o`.`UnitPrice`)) IS NULL, NULL, CSNG(INT(CSNG(`o`.`UnitPrice`))))
1610+
SELECT IIF(FIX(CSNG(`o`.`UnitPrice`)) IS NULL, NULL, CSNG(FIX(CSNG(`o`.`UnitPrice`))))
16111611
FROM `Order Details` AS `o`
16121612
WHERE `o`.`Quantity` < 5
16131613
""");

0 commit comments

Comments
 (0)