【发布时间】:2019-03-25 01:25:44
【问题描述】:
我正在使用这个 Linq to sql 来获取出现最多的记录。
List<int> result;
result = await context.InvoiceItems.GroupBy(q => q.ProductID)
.OrderByDescending(gp => gp.Count())
.Take(5)
.Select(g => g.Key).ToListAsync();
并获取 int 类型值。但我也想获得每个值出现的总次数。就像这个 SQL 查询正在返回。
select productID, Count(*) AS value_occurrence from InvoiceItems group by productID
查看这张桌子图片
【问题讨论】:
标签: c# sql linq-to-sql