From 59a021c33d63ad710d8187577f0eee2305f68c8c Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Thu, 5 Mar 2026 13:31:54 +0100 Subject: [PATCH] Fix casting. --- .../Providers/MySql/JsonFunction.cs | 5 +++-- .../Providers/Postgres/JsonFunction.cs | 15 ++++++++++++--- .../Squidex.Data.EntityFramework.csproj | 1 - .../Infrastructure/Queries/EFQueryTests.cs | 11 +++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/backend/src/Squidex.Data.EntityFramework/Providers/MySql/JsonFunction.cs b/backend/src/Squidex.Data.EntityFramework/Providers/MySql/JsonFunction.cs index 1f5736189..69f763db6 100644 --- a/backend/src/Squidex.Data.EntityFramework/Providers/MySql/JsonFunction.cs +++ b/backend/src/Squidex.Data.EntityFramework/Providers/MySql/JsonFunction.cs @@ -111,11 +111,12 @@ public static class JsonFunction return $"{fn}(`{path[0]}`, {path.JsonSubPath()})"; } + var arg = formattedValue; if (value.IsList) { - return $"{fn}(`{path[0]}`, {path.JsonSubPath()}, JSON_ARRAY({formattedValue}))"; + arg = $"JSON_ARRAY({formattedValue})"; } - return $"{fn}(`{path[0]}`, {path.JsonSubPath()}, {formattedValue})"; + return $"{fn}(`{path[0]}`, {path.JsonSubPath()}, {arg})"; } } diff --git a/backend/src/Squidex.Data.EntityFramework/Providers/Postgres/JsonFunction.cs b/backend/src/Squidex.Data.EntityFramework/Providers/Postgres/JsonFunction.cs index c9abf958a..168af3e56 100644 --- a/backend/src/Squidex.Data.EntityFramework/Providers/Postgres/JsonFunction.cs +++ b/backend/src/Squidex.Data.EntityFramework/Providers/Postgres/JsonFunction.cs @@ -101,11 +101,20 @@ public static class JsonFunction return $"{fn}({path.JsonPath(false)})"; } - if (value.IsList) + var arg = formattedValue; + if (value.IsList && type == TypeNumber) { - return $"{fn}({path.JsonPath(false)}, ARRAY[{formattedValue}])"; + arg = $"ARRAY[{formattedValue}]::numeric[]"; + } + else if (value.IsList) + { + arg = $"ARRAY[{formattedValue}]"; + } + else if (type == TypeNumber) + { + arg = $"{formattedValue}::numeric"; } - return $"{fn}({path.JsonPath(false)}, {formattedValue})"; + return $"{fn}({path.JsonPath(false)}, {arg})"; } } diff --git a/backend/src/Squidex.Data.EntityFramework/Squidex.Data.EntityFramework.csproj b/backend/src/Squidex.Data.EntityFramework/Squidex.Data.EntityFramework.csproj index a44891558..0945d8303 100644 --- a/backend/src/Squidex.Data.EntityFramework/Squidex.Data.EntityFramework.csproj +++ b/backend/src/Squidex.Data.EntityFramework/Squidex.Data.EntityFramework.csproj @@ -11,7 +11,6 @@ True - diff --git a/backend/tests/Squidex.Data.Tests/EntityFramework/Infrastructure/Queries/EFQueryTests.cs b/backend/tests/Squidex.Data.Tests/EntityFramework/Infrastructure/Queries/EFQueryTests.cs index d879e5cae..e4dce705a 100644 --- a/backend/tests/Squidex.Data.Tests/EntityFramework/Infrastructure/Queries/EFQueryTests.cs +++ b/backend/tests/Squidex.Data.Tests/EntityFramework/Infrastructure/Queries/EFQueryTests.cs @@ -384,6 +384,17 @@ public abstract class EFQueryTests(ISqlFixture fixture) Assert.Equal([7], actual.Order().ToArray()); } + [Fact] + public async Task Should_filter_by_number_equal_with_double() + { + var actual = await QueryAsync(new ClrQuery + { + Filter = ClrFilter.Eq("Number", 7.0), + }); + + Assert.Equal([7], actual.Order().ToArray()); + } + [Fact] public async Task Should_filter_by_number_not_equal() {