Is it possible in LINQ to do this: Group by a field (LineTotal), returning only the top 9 groups and then in the 10th group return the sum of all other groups?
In SQL server this can be done like so:
with TopGroups as
(
select sum(sol.LineTotal) as ProductGroupSales, p.ProductGroupId,
ROW_NUMBER() OVER(ORDER BY sum(sol.LineTotal) DESC) as Num
from SalesOrderLines sol left join Products p on p.Id = sol.ProductId
group by p.ProductGroupId
)
select ProductGroupSales from TopGroups where Num < 10
union all
select sum(ProductGroupSales) from TopGroups where Num >= 10
Can this be translated to LINQ? I’m not sure how ROW_NUMBER() OVER() and union all translate to LINQ.
.Take(9)” and “.Skip(0).Take(1)“.UNION ALLmaps toseqA.Concat(seqB)–
All of these basically come at no performance cost on the SQL side.