diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs index 60c3f13e46e..0de6635e2a0 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs @@ -42,11 +42,17 @@ public class SqliteMathTranslator : IMethodCallTranslator { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(ushort), typeof(ushort) })!, "min" }, { typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double) })!, "round" }, { typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double), typeof(int) })!, "round" }, + { typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(double) })!, "sign" }, + { typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(float) })!, "sign" }, + { typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(long) })!, "sign" }, + { typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(sbyte) })!, "sign" }, + { typeof(Math).GetMethod(nameof(Math.Sign), new[] { typeof(short) })!, "sign" }, { typeof(MathF).GetMethod(nameof(MathF.Abs), new[] { typeof(float) })!, "abs" }, { typeof(MathF).GetMethod(nameof(MathF.Max), new[] { typeof(float), typeof(float) })!, "max" }, { typeof(MathF).GetMethod(nameof(MathF.Min), new[] { typeof(float), typeof(float) })!, "min" }, { typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float) })!, "round" }, - { typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float), typeof(int) })!, "round" } + { typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float), typeof(int) })!, "round" }, + { typeof(MathF).GetMethod(nameof(MathF.Sign), new[] { typeof(float) })!, "sign" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; @@ -78,7 +84,7 @@ public SqliteMathTranslator(ISqlExpressionFactory sqlExpressionFactory) { RelationalTypeMapping? typeMapping; List? newArguments = null; - if (sqlFunctionName == "max" || sqlFunctionName == "max") + if (sqlFunctionName == "max" || sqlFunctionName == "min") { typeMapping = ExpressionExtensions.InferTypeMapping(arguments[0], arguments[1]); newArguments = new List diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindFunctionsQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindFunctionsQuerySqliteTest.cs index 75b71e662be..50d5d8b3b19 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindFunctionsQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindFunctionsQuerySqliteTest.cs @@ -120,8 +120,17 @@ public override Task Sum_over_truncate_works_correctly_in_projection_2(bool asyn public override Task Where_math_round2(bool async) => AssertTranslationFailed(() => base.Where_math_round2(async)); - public override Task Where_math_sign(bool async) - => AssertTranslationFailed(() => base.Where_math_sign(async)); + public override async Task Where_math_sign(bool async) + { + await base.Where_math_sign(async); + + AssertSql( +""" +SELECT "o"."OrderID", "o"."ProductID", "o"."Discount", "o"."Quantity", "o"."UnitPrice" +FROM "Order Details" AS "o" +WHERE "o"."OrderID" = 11077 AND sign("o"."Discount") > 0 +"""); + } public override Task Where_math_sin(bool async) => AssertTranslationFailed(() => base.Where_math_sin(async)); @@ -174,8 +183,17 @@ public override Task Where_mathf_power(bool async) public override Task Where_mathf_square(bool async) => AssertTranslationFailed(() => base.Where_mathf_square(async)); - public override Task Where_mathf_sign(bool async) - => AssertTranslationFailed(() => base.Where_mathf_sign(async)); + public override async Task Where_mathf_sign(bool async) + { + await base.Where_mathf_sign(async); + + AssertSql( +""" +SELECT "o"."OrderID", "o"."ProductID", "o"."Discount", "o"."Quantity", "o"."UnitPrice" +FROM "Order Details" AS "o" +WHERE "o"."OrderID" = 11077 AND sign("o"."Discount") > 0 +"""); + } public override Task Where_mathf_sin(bool async) => AssertTranslationFailed(() => base.Where_mathf_sin(async));