Linq order by grouped count before select clause gives wrong sql

Details

Description

The following test is a variation of the test in
NH-2560
Closed
. That test works now, after recent commits. This variation puts the ordering expression inside the call to OrderBy(), before the projection. This fails due to flawed SQL.

Test
public void SingleKeyPropertyGroupAndOrderByCountBeforeProjection()
{
// This is a variation of SingleKeyPropertyGroupAndOrderByProjectedCount()
// that puts the ordering expression inside the OrderBy, without first
// going through a select clause.

The generated SQL. Notice missing count in the order by clause. There is also a superflouos join, but I suspect that may be covered by
NH-3003
Closed
.

select
customer1_.CustomerId as col_0_0_,
cast(count as INT) as col_1_0_
from
Orders order0_
left outer join
Customers customer1_
on order0_.CustomerId=customer1_.CustomerId
group by
customer1_.CustomerId
order by
order0_.OrderId desc