diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs index 0fa1e853271..656d144b856 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs @@ -173,9 +173,9 @@ protected virtual void GenerateJsonEach(JsonEachExpression jsonEachExpression) } else { - Sql.Append("' + "); + Sql.Append("' || "); Visit(arrayIndex); - Sql.Append(" + '"); + Sql.Append(" || '"); } Sql.Append("]"); diff --git a/test/EFCore.Relational.Specification.Tests/Query/JsonQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/JsonQueryTestBase.cs index 26ba6f29b4f..9c6f4625630 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/JsonQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/JsonQueryTestBase.cs @@ -968,8 +968,8 @@ public virtual Task Json_collection_Where_ElementAt(bool async) async, ss => ss.Set().Where(j => j.OwnedReferenceRoot.OwnedCollectionBranch - .Where(o => o.Date == new DateTime(2102, 1, 1)) - .ElementAt(0).Fraction == 10.2M), + .Where(o => o.Enum == JsonEnum.Three) + .ElementAt(0).OwnedReferenceLeaf.SomethingSomething == "e1_r_c2_r"), entryCount: 40); [ConditionalTheory] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/JsonQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/JsonQuerySqlServerTest.cs index e3dadfa10d2..f520582ca59 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/JsonQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/JsonQuerySqlServerTest.cs @@ -944,11 +944,11 @@ public override async Task Json_collection_Where_ElementAt(bool async) SELECT [j].[Id], [j].[EntityBasicId], [j].[Name], [j].[OwnedCollectionRoot], [j].[OwnedReferenceRoot] FROM [JsonEntitiesBasic] AS [j] WHERE ( - SELECT CAST(JSON_VALUE([o].[value], '$.Fraction') AS decimal(18,2)) + SELECT JSON_VALUE([o].[value], '$.OwnedReferenceLeaf.SomethingSomething') FROM OPENJSON([j].[OwnedReferenceRoot], '$.OwnedCollectionBranch') AS [o] - WHERE CAST(JSON_VALUE([o].[value], '$.Date') AS datetime2) = '2102-01-01T00:00:00.0000000' + WHERE JSON_VALUE([o].[value], '$.Enum') = N'Three' ORDER BY CAST([o].[key] AS int) - OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY) = 10.2 + OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY) = N'e1_r_c2_r' """); } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/JsonQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/JsonQuerySqliteTest.cs index 2964f93c76c..07777fcc77f 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/JsonQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/JsonQuerySqliteTest.cs @@ -85,6 +85,26 @@ FROM json_each("j"."OwnedReferenceRoot", '$.OwnedCollectionBranch') AS "o" """); } + public override async Task Json_collection_Where_ElementAt(bool async) + { + await base.Json_collection_Where_ElementAt(async); + + AssertSql( +""" +SELECT "j"."Id", "j"."EntityBasicId", "j"."Name", "j"."OwnedCollectionRoot", "j"."OwnedReferenceRoot" +FROM "JsonEntitiesBasic" AS "j" +WHERE ( + SELECT "t"."OwnedReferenceLeaf" ->> 'SomethingSomething' + FROM ( + SELECT "o"."value" ->> 'Date' AS "Date", "o"."value" ->> 'Enum' AS "Enum", "o"."value" ->> 'Fraction' AS "Fraction", "o"."value" ->> 'NullableEnum' AS "NullableEnum", "o"."value" ->> 'OwnedCollectionLeaf' AS "OwnedCollectionLeaf", "o"."value" ->> 'OwnedReferenceLeaf' AS "OwnedReferenceLeaf", "j"."Id", "o"."key" + FROM json_each("j"."OwnedReferenceRoot", '$.OwnedCollectionBranch') AS "o" + ) AS "t" + WHERE "t"."Enum" = 'Three' + ORDER BY "t"."key" + LIMIT 1 OFFSET 0) = 'e1_r_c2_r' +"""); + } + public override async Task Json_collection_Skip(bool async) { await base.Json_collection_Skip(async); @@ -156,6 +176,13 @@ FROM json_each("t"."OwnedCollectionBranch", '$') AS "o0" """); } + public override async Task Json_collection_Select_entity_with_initializer_ElementAt(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Project_json_entity_FirstOrDefault_subquery_deduplication_outer_reference_and_pruning(async))) + .Message); + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual async Task FromSqlInterpolated_on_entity_with_json_with_predicate(bool async)