Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Jun 19, 2023
1 parent 558b775 commit 847dc09
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ protected virtual void GenerateJsonEach(JsonEachExpression jsonEachExpression)
}
else
{
Sql.Append("' + ");
Sql.Append("' || ");
Visit(arrayIndex);
Sql.Append(" + '");
Sql.Append(" || '");
}

Sql.Append("]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,8 @@ public virtual Task Json_collection_Where_ElementAt(bool async)
async,
ss => ss.Set<JsonEntityBasic>().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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
""");
}

Expand Down
27 changes: 27 additions & 0 deletions test/EFCore.Sqlite.FunctionalTests/Query/JsonQuerySqliteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<InvalidOperationException>(
() => 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)
Expand Down

0 comments on commit 847dc09

Please sign in to comment.