You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query: GroupBy with aggregation on navigation property evaluated on the client #11813
Navigation members in GroupBy or just in aggregation expressions executed server side, however if you use GroupBy and aggregation for navigation member it happens client side.
Steps to reproduce
GroupByQuerySqlServerTest.GroupBy_with_aggregate_through_navigation_property shows the issue
publicoverridevoidGroupBy_with_aggregate_through_navigation_property(){base.GroupBy_with_aggregate_through_navigation_property();AssertSql(@"SELECT [c].[OrderID], [c].[CustomerID], [c].[EmployeeID], [c].[OrderDate]FROM [Orders] AS [c]ORDER BY [c].[EmployeeID]",//@"SELECT [i.Customer0].[CustomerID], [i.Customer0].[Region]FROM [Customers] AS [i.Customer0]",//@"SELECT [i.Customer0].[CustomerID], [i.Customer0].[Region]FROM [Customers] AS [i.Customer0]");}[ConditionalFact]publicvirtualvoidGroupBy_with_aggregate_through_navigation_property(){AssertQuery<Order>(
os =>os.GroupBy(c =>c.EmployeeID).Select(g =>new{max=g.Max(i =>i.Customer.Region)}),elementSorter: e =>e.max);}
However, proper SQL should look like
SELECT [o].[EmployeeID], MAX([o.Customer].[Region]) AS [Region]
FROM [Orders] AS [o]
INNER JOIN [Customers] AS [o.Customer] ON [o].[CustomerID] = [od.Customer].[CustoemrID]
GROUP BY [o].[EmployeeID]
This really needs to be highlighted in the documentation, it took me a while to find this issue and understand that the GroupBy translation still isn't fully implemented. The documentation states "We now support translating it to the SQL GROUP BY clause in most common cases." and this is a very common use case.
The behavior I'm noticing is that even a simple query to select the key of the parent table and a count of child records with a where clause restricting the parent ID to a single record issues two selects:
One that retrieves all properties for the parent
A second that retrieves all of the child records with no restriction
Obviously this isn't usable in most real world scenarios.
changed the title [-]Query: GroupBy with aggregation on navigation property evaludated on the client [/-][+]Query: GroupBy with aggregation on navigation property evaluated on the client [/+]on May 23, 2018
Activity
jamieide commentedon May 14, 2018
This really needs to be highlighted in the documentation, it took me a while to find this issue and understand that the GroupBy translation still isn't fully implemented. The documentation states "We now support translating it to the SQL GROUP BY clause in most common cases." and this is a very common use case.
The behavior I'm noticing is that even a simple query to select the key of the parent table and a count of child records with a where clause restricting the parent ID to a single record issues two selects:
Obviously this isn't usable in most real world scenarios.
[-]Query: GroupBy with aggregation on navigation property evaludated on the client [/-][+]Query: GroupBy with aggregation on navigation property evaluated on the client [/+]ajcvickers commentedon May 24, 2018
Added a note to #12089 to test this scenario and closing as dupe.
divega commentedon Dec 12, 2018
Clearing up milestone since I think I heard @smitpatel say that this kind of query will be translate in 3.0.