diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs index 2644ef6ffc0..a60786ee949 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs @@ -110,6 +110,13 @@ public NavigationExpandingExpressionVisitor( public virtual Expression Expand(Expression query) { var result = Visit(query); + + if (result is GroupByNavigationExpansionExpression) + { + // This indicates that GroupBy was not condensed out of grouping operator. + throw new InvalidOperationException(CoreStrings.TranslationFailed(query.Print())); + } + result = new PendingSelectorExpandingExpressionVisitor(this, _extensibilityHelper, applyIncludes: true).Visit(result); result = Reduce(result); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs index f11d23ba64b..b814c7bd6f5 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindGroupByQueryTestBase.cs @@ -2750,6 +2750,34 @@ public virtual Task GroupBy_group_Where_Select_Distinct_aggregate(bool async) #region GroupByWithoutAggregate + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task GroupBy_as_final_operator(bool async) + { + return AssertTranslationFailed(() => AssertQuery( + async, + ss => ss.Set().GroupBy(c => c.City))); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task GroupBy_Where_with_grouping_result(bool async) + { + return AssertTranslationFailed(() => AssertQuery( + async, + ss => ss.Set().GroupBy(c => c.City).Where(e => e.Key.StartsWith("s")))); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task GroupBy_OrderBy_with_grouping_result(bool async) + { + return AssertTranslationFailed(() => AssertQuery( + async, + ss => ss.Set().GroupBy(c => c.City).OrderBy(e => e.Key), + assertOrder: true)); + } + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task GroupBy_SelectMany(bool async)