NotSupportedException when using Skip/Take/First/Single/Any on GroupBy

Description

The following fails with NotSupportedException from the NonAggregatingGroupByRewriter.FlattenSubQuery method.

[Test]
public void SingleKeyPropertyGroupWithOrderBy()
{
var results = (from o in db.Orders
group o by o.Customer
into g
select g.Key)
.Skip(10)
.Take(10)
.ToList();
}

Environment

None

Activity

Show:

Alex Zaytsev September 8, 2014 at 11:31 AM

Close issues resolved in 3.3.3

Oskar Berggren November 24, 2012 at 10:44 PM

Fix for groupby and Any() from Dmitry merged in 056e57b6870aef4c169ecc254d33b9d1236c54ec (3.3.x).

Oskar Berggren November 17, 2012 at 10:52 AM

The issue with grouping by an entity and returning the whole entity is NH-3027.

Oskar Berggren November 17, 2012 at 2:09 AM

Fixed in 688d00ff1736f3b0c3e018ed5f57bc97267baff7 (and adjoining) by patch from Dmitry.

The fix is for a slightly modified query:
var results = (from o in db.Orders
group o by o.Customer into g
select g.Key.CustomerId)
.Skip(10)
.Take(10)
.ToList();

The difference is that we take the CustomerId on g.Key. Without this change NH will try to fetch all columns from customer while only grouping on the customer ID, which is or course not valid SQL. Possible that could be solved by having NH put the grouping etc in a subquery and then add the other columns in an outer query. But that would be a matter for another bug report.

Oskar Berggren November 15, 2012 at 3:30 PM

Sounds similar to NH-3320.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created March 9, 2011 at 4:39 AM
Updated September 8, 2014 at 11:31 AM
Resolved November 17, 2012 at 2:09 AM
Who's Looking?