From 6f773140bb989115709c6b6e89e4d29e5e994ce0 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Tue, 25 Apr 2023 09:16:36 +0200 Subject: [PATCH] Review comments --- ...onalQueryableMethodTranslatingExpressionVisitor.cs | 2 +- .../SqlServerDbContextOptionsBuilder.cs | 1 - ...aredPrimitiveCollectionsQueryRelationalTestBase.cs | 3 +++ ...NonSharedPrimitiveCollectionsQuerySqlServerTest.cs | 10 ++++++++++ .../NonSharedPrimitiveCollectionsQuerySqliteTest.cs | 11 +++++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index e043297df61..5c5774da1df 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -2822,7 +2822,7 @@ protected virtual ValuesExpression ApplyTypeMappingsOnValuesExpression(ValuesExp for (var i = 0; i < newRowValues.Length; i++) { var rowValue = valuesExpression.RowValues[i]; - var newValues = new SqlExpression[valuesExpression.ColumnNames.Count - (stripOrdering ? 1 : 0)]; + var newValues = new SqlExpression[newColumnNames.Count]; for (var j = 0; j < valuesExpression.ColumnNames.Count; j++) { Check.DebugAssert(rowValue.Values[j] is SqlConstantExpression, "Non-constant SqlExpression in ValuesExpression"); diff --git a/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs b/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs index 6c537a89571..066f6eccc03 100644 --- a/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs +++ b/src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs @@ -114,7 +114,6 @@ public virtual SqlServerDbContextOptionsBuilder EnableRetryOnFailure( /// documentation on compatibility level for more information and examples. /// /// to have null resource - // TODO: Naming; Cosmos doesn't have Use/Set, so just CompatibilityLevel? SetCompatibilityLevel? public virtual SqlServerDbContextOptionsBuilder UseCompatibilityLevel(int compatibilityLevel) => WithOption(e => e.WithCompatibilityLevel(compatibilityLevel)); } diff --git a/test/EFCore.Relational.Specification.Tests/Query/NonSharedPrimitiveCollectionsQueryRelationalTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/NonSharedPrimitiveCollectionsQueryRelationalTestBase.cs index 43da781f406..19d33e77f10 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/NonSharedPrimitiveCollectionsQueryRelationalTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/NonSharedPrimitiveCollectionsQueryRelationalTestBase.cs @@ -27,6 +27,9 @@ public virtual async Task Column_collection_inside_json_owned_entity() var result = await context.Set().SingleAsync(o => o.Owned.Strings.Count() == 2); Assert.Equivalent(new[] { "foo", "bar" }, result.Owned.Strings); + + result = await context.Set().SingleAsync(o => o.Owned.Strings[1] == "bar"); + Assert.Equivalent(new[] { "foo", "bar" }, result.Owned.Strings); } protected class TestOwner diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqlServerTest.cs index fe10dc02a9a..947b7f192c6 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqlServerTest.cs @@ -265,6 +265,16 @@ FROM [TestOwner] AS [t] WHERE ( SELECT COUNT(*) FROM OpenJson(JSON_VALUE([t].[Owned], '$.Strings')) AS [s]) = 2 +""", + // +""" +SELECT TOP(2) [t].[Id], [t].[Owned] +FROM [TestOwner] AS [t] +WHERE ( + SELECT [s].[value] + FROM OpenJson(JSON_VALUE([t].[Owned], '$.Strings')) AS [s] + ORDER BY CAST([s].[key] AS int) + OFFSET 1 ROWS FETCH NEXT 1 ROWS ONLY) = N'bar' """); } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqliteTest.cs index c5dd4d5ba7f..bcb8ee1d733 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqliteTest.cs @@ -224,6 +224,17 @@ public override async Task Column_collection_inside_json_owned_entity() FROM "TestOwner" AS "t" WHERE json_array_length(json_extract("t"."Owned", '$.Strings')) = 2 LIMIT 2 +""", + // +""" +SELECT "t"."Id", "t"."Owned" +FROM "TestOwner" AS "t" +WHERE ( + SELECT "s"."value" + FROM json_each(json_extract("t"."Owned", '$.Strings')) AS "s" + ORDER BY "s"."key" + LIMIT 1 OFFSET 1) = 'bar' +LIMIT 2 """); }