diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index 2041d77b5d3..c76b3b3dcea 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -7548,6 +7548,28 @@ public virtual Task Projecting_required_string_column_compared_to_null_parameter ss => ss.Set().Select(g => g.Nickname == nullParameter)); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Group_by_nullable_property_HasValue_and_project_the_grouping_key(bool async) + { + return AssertQueryScalar( + async, + ss => ss.Set() + .GroupBy(w => w.SynergyWithId.HasValue) + .Select(g => g.Key)); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Group_by_nullable_property_and_project_the_grouping_key_HasValue(bool async) + { + return AssertQueryScalar( + async, + ss => ss.Set() + .GroupBy(w => w.SynergyWithId) + .Select(g => g.Key.HasValue)); + } + protected GearsOfWarContext CreateContext() => Fixture.CreateContext(); protected virtual void ClearLog() diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index 1ce6e0e44d2..10f2d098034 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -7527,6 +7527,35 @@ FROM [Gears] AS [g] WHERE [g].[Discriminator] IN (N'Gear', N'Officer')"); } + public override async Task Group_by_nullable_property_HasValue_and_project_the_grouping_key(bool async) + { + await base.Group_by_nullable_property_HasValue_and_project_the_grouping_key(async); + + AssertSql( + @"SELECT CASE + WHEN [w].[SynergyWithId] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +FROM [Weapons] AS [w] +GROUP BY CASE + WHEN [w].[SynergyWithId] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END"); + } + + public override async Task Group_by_nullable_property_and_project_the_grouping_key_HasValue(bool async) + { + await base.Group_by_nullable_property_and_project_the_grouping_key_HasValue(async); + + AssertSql( + @"SELECT CASE + WHEN [w].[SynergyWithId] IS NOT NULL THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) +END +FROM [Weapons] AS [w] +GROUP BY [w].[SynergyWithId]"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); }