diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs index b515ca316cb..b8fde3f25da 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs @@ -1308,6 +1308,12 @@ public override Task Client_projection_via_ctor_arguments(bool async) return base.Client_projection_via_ctor_arguments(async); } + [ConditionalTheory(Skip = "Cross collection join Issue#17246")] + public override Task Client_projection_with_string_initialization_with_scalar_subquery(bool async) + { + return base.Client_projection_with_string_initialization_with_scalar_subquery(async); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs index 11fdc69177f..9451a5b9d90 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs @@ -2373,5 +2373,53 @@ public OrderInfo(int orderID, DateTime? orderDate) public DateTime? OrderDate { get; } } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Client_projection_with_string_initialization_with_scalar_subquery(bool async) + { + return AssertQuery( + async, + ss => ss.Set() + .Where(c => c.CustomerID.StartsWith("F")) + .Select(c => new + { + c.CustomerID, + Order = c.Orders.FirstOrDefault(o => o.OrderID < 11000).OrderDate, + InterpolatedString = $"test{c.City}", + NonInterpolatedString = "test" + c.City, + Collection = new List + { + $"{c.CustomerID}@test1.com", + $"{c.CustomerID}@test2.com", + $"{c.CustomerID}@test3.com", + $"{c.CustomerID}@test4.com" + } + }), + ss => ss.Set() + .Where(c => c.CustomerID.StartsWith("F")) + .Select(c => new + { + c.CustomerID, + Order = c.Orders.FirstOrDefault(o => o.OrderID < 11000).MaybeScalar(e => e.OrderDate), + InterpolatedString = $"test{c.City}", + NonInterpolatedString = "test" + c.City, + Collection = new List + { + $"{c.CustomerID}@test1.com", + $"{c.CustomerID}@test2.com", + $"{c.CustomerID}@test3.com", + $"{c.CustomerID}@test4.com" + } + }), + elementSorter: e => e.CustomerID, + elementAsserter: (e, a) => + { + AssertEqual(e.CustomerID, a.CustomerID); + AssertEqual(e.Order, a.Order); + AssertEqual(e.InterpolatedString, a.InterpolatedString); + AssertEqual(e.NonInterpolatedString, a.NonInterpolatedString); + AssertCollection(e.Collection, a.Collection, ordered: true); + }); + } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs index ae5f7b271fd..809b4b1b204 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs @@ -1842,6 +1842,19 @@ FROM [Customers] AS [c] ORDER BY [t].[CustomerID]"); } + public override async Task Client_projection_with_string_initialization_with_scalar_subquery(bool async) + { + await base.Client_projection_with_string_initialization_with_scalar_subquery(async); + + AssertSql( + @"SELECT [c].[CustomerID], ( + SELECT TOP(1) [o].[OrderDate] + FROM [Orders] AS [o] + WHERE ([c].[CustomerID] = [o].[CustomerID]) AND ([o].[OrderID] < 11000)), [c].[City], N'test' + COALESCE([c].[City], N'') +FROM [Customers] AS [c] +WHERE [c].[CustomerID] LIKE N'F%'"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected);