diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index e8dc80d3881..59dd62ac8f5 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -7668,6 +7668,15 @@ public virtual Task OfType_in_subquery_works(bool isAsync) os => os.SelectMany(o => o.Reports.OfType().Select(o1 => o1.AssignedCity))); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Nullable_bool_comparison_is_translated_to_server(bool isAsync) + { + return AssertQuery( + isAsync, + lhs => lhs.Select(lh => new { IsEradicated = lh.Eradicated == true })); + } + protected GearsOfWarContext CreateContext() => Fixture.CreateContext(); protected virtual void ClearLog() diff --git a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs index 6d19c61c816..b7924faeacf 100644 --- a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs +++ b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs @@ -56,6 +56,11 @@ public virtual IQueryable Set() return (IQueryable)Factions.AsQueryable(); } + if (typeof(TEntity) == typeof(LocustHorde)) + { + return (IQueryable)Factions.OfType().AsQueryable(); + } + if (typeof(TEntity) == typeof(Gear)) { return (IQueryable)Gears.AsQueryable(); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index 42226788979..95c0099d03e 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -7157,6 +7157,19 @@ WHERE [g0].[Discriminator] IN (N'Gear', N'Officer') AND ([g0].[Discriminator] = WHERE [g].[Discriminator] = N'Officer'"); } + public override async Task Nullable_bool_comparison_is_translated_to_server(bool isAsync) + { + await base.Nullable_bool_comparison_is_translated_to_server(isAsync); + + AssertSql( + @"SELECT CASE + WHEN ([f].[Eradicated] = CAST(1 AS bit)) AND [f].[Eradicated] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END AS [IsEradicated] +FROM [Factions] AS [f] +WHERE [f].[Discriminator] = N'LocustHorde'"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); }