diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs index ee716804188..0a26c46186e 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs @@ -5559,5 +5559,14 @@ public virtual Task OrderBy_collection_count_ThenBy_reference_navigation(bool as () => l1.OneToOne_Required_FK1.OneToOne_Required_FK2.Name)), assertOrder: true); } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Null_conditional_is_not_applied_explicitly_for_optional_navigation(bool async) + { + return AssertQuery( + async, + ss => ss.Set().Where(l1 => l1.OneToOne_Optional_FK1 != null && l1.OneToOne_Optional_FK1.Name == "L2 01")); + } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs index b2ec403e7e0..f139796df15 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs @@ -4301,6 +4301,17 @@ FROM [LevelThree] AS [l2] WHERE [l0].[Id] IS NOT NULL AND ([l0].[Id] = [l2].[OneToMany_Required_Inverse3Id])), [l1].[Name]"); } + public override async Task Null_conditional_is_not_applied_explicitly_for_optional_navigation(bool async) + { + await base.Null_conditional_is_not_applied_explicitly_for_optional_navigation(async); + + AssertSql( + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +WHERE [l0].[Id] IS NOT NULL AND ([l0].[Name] = N'L2 01')"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); } }