diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index 2e4d11e06e7..81632937eb2 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -7268,6 +7268,20 @@ public virtual Task Cast_OfType_works_correctly(bool async) ss => ss.Set().Cast().OfType().Select(o => o.FullName)); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Join_inner_source_custom_projection_followed_by_filter(bool async) + { + return AssertQuery( + async, + ss => from ll in ss.Set() + join h in ss.Set().OfType() + .Select(f => new { IsEradicated = f.Name == "Locust" ? (bool?)true : null, f.CommanderName, f.Name }) + on ll.Name equals h.CommanderName + where h.IsEradicated != true + select h); + } + protected async Task AssertTranslationFailed(Func testCode) { Assert.Contains( diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index 3518b44a299..5d33451cba6 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -7241,6 +7241,30 @@ FROM [Gears] AS [g] WHERE [g].[Discriminator] IN (N'Gear', N'Officer') AND ([g].[Discriminator] = N'Officer')"); } + public override async Task Join_inner_source_custom_projection_followed_by_filter(bool async) + { + await base.Join_inner_source_custom_projection_followed_by_filter(async); + + AssertSql( + @"SELECT CASE + WHEN [t].[Name] = N'Locust' THEN CAST(1 AS bit) + ELSE NULL +END AS [IsEradicated], [t].[CommanderName], [t].[Name] +FROM [LocustLeaders] AS [l] +INNER JOIN ( + SELECT [f].[Id], [f].[CapitalName], [f].[Discriminator], [f].[Name], [f].[CommanderName], [f].[Eradicated] + FROM [Factions] AS [f] + WHERE ([f].[Discriminator] = N'LocustHorde') AND ([f].[Discriminator] = N'LocustHorde') +) AS [t] ON [l].[Name] = [t].[CommanderName] +WHERE [l].[Discriminator] IN (N'LocustLeader', N'LocustCommander') AND ((CASE + WHEN [t].[Name] = N'Locust' THEN CAST(1 AS bit) + ELSE NULL +END <> CAST(1 AS bit)) OR CASE + WHEN [t].[Name] = N'Locust' THEN CAST(1 AS bit) + ELSE NULL +END IS NULL)"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); }