diff --git a/test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs index 0e302e2becf..7891d0ae0b2 100644 --- a/test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs @@ -748,6 +748,14 @@ public virtual Task Project_collection_of_nullable_ints_with_distinct(bool async assertOrder: true, elementAsserter: (e, a) => AssertCollection(e, a, elementSorter: ee => ee)); + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Project_collection_of_ints_with_ToList_and_FirstOrDefault(bool async) + => AssertFirstOrDefault( + async, + ss => ss.Set().OrderBy(x => x.Id).Select(x => x.Ints.ToList()), + asserter: (e, a) => AssertCollection(e, a, elementSorter: ee => ee)); + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Project_empty_collection_of_nullables_and_collection_only_containing_nulls(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQueryOldSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQueryOldSqlServerTest.cs index 2117994b0e9..9a78d37f910 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQueryOldSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQueryOldSqlServerTest.cs @@ -589,6 +589,18 @@ public override async Task Project_collection_of_nullable_ints_with_distinct(boo AssertSql(""); } + public override async Task Project_collection_of_ints_with_ToList_and_FirstOrDefault(bool async) + { + await base.Project_collection_of_ints_with_ToList_and_FirstOrDefault(async); + + AssertSql( + """ +SELECT TOP(1) [p].[Ints] +FROM [PrimitiveCollectionsEntity] AS [p] +ORDER BY [p].[Id] +"""); + } + public override Task Project_multiple_collections(bool async) // we don't propagate error details from projection => AssertTranslationFailed(() => base.Project_multiple_collections(async)); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs index 970e6cbdbc9..b7016e96076 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs @@ -1168,6 +1168,23 @@ public override async Task Project_collection_of_nullable_ints_with_distinct(boo AssertSql(""); } + public override async Task Project_collection_of_ints_with_ToList_and_FirstOrDefault(bool async) + { + await base.Project_collection_of_ints_with_ToList_and_FirstOrDefault(async); + + AssertSql( + """ +SELECT [t].[Id], CAST([i].[value] AS int) AS [value], [i].[key] +FROM ( + SELECT TOP(1) [p].[Id], [p].[Ints] + FROM [PrimitiveCollectionsEntity] AS [p] + ORDER BY [p].[Id] +) AS [t] +OUTER APPLY OPENJSON([t].[Ints]) AS [i] +ORDER BY [t].[Id], CAST([i].[key] AS int) +"""); + } + public override async Task Project_empty_collection_of_nullables_and_collection_only_containing_nulls(bool async) { await base.Project_empty_collection_of_nullables_and_collection_only_containing_nulls(async); diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/PrimitiveCollectionsQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/PrimitiveCollectionsQuerySqliteTest.cs index a6ac3d00ff9..83d46064923 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/PrimitiveCollectionsQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/PrimitiveCollectionsQuerySqliteTest.cs @@ -1084,6 +1084,12 @@ public override async Task Project_collection_of_nullable_ints_with_distinct(boo (await Assert.ThrowsAsync( () => base.Project_collection_of_nullable_ints_with_distinct(async))).Message); + public override async Task Project_collection_of_ints_with_ToList_and_FirstOrDefault(bool async) + => Assert.Equal( + SqliteStrings.ApplyNotSupported, + (await Assert.ThrowsAsync( + () => base.Project_collection_of_ints_with_ToList_and_FirstOrDefault(async))).Message); + public override async Task Project_multiple_collections(bool async) => Assert.Equal( SqliteStrings.ApplyNotSupported,