我的控制器中有以下 LINQ 查询,它查询我的 IEnumerable 集合,当我在视图中输出结果时,分组工作,但是当我尝试在我分组的列上添加计数时,它惨遭失败。我想知道是否有人可以提供帮助,我一直在查看以前的示例,但我遗漏了一些明显的东西。
Grouped //工作正常并返回分组描述
itemdetails = (from c in db.CLIENTDETAILS
join l in db.LOCATIONS on c.CLIENTNUMBER equals l.CLIENTNUMBER
where c.CLIENTNUMBER == clientNumber
join i in db.ITEMDETAILS on l.LOCNUMBER equals i.LOCNUMBER
where i.LOCNUMBER == l.LOCNUMBER
select i).GroupBy(it => it.DESC).Select(grp => grp.FirstOrDefault()).OrderBy(x => x.DESC)
我试图在 LINQ 中获取 Group 和 Count //Not working 返回错误
itemdetails = (from c in db.CLIENTDETAILS
join l in db.LOCATIONS on c.CLIENTNUMBER equals l.CLIENTNUMBER
where c.CLIENTNUMBER == clientNumber
join i in db.ITEMDETAILS on l.LOCNUMBER equals i.LOCNUMBER
where i.LOCNUMBER == l.LOCNUMBER
select i).GroupBy(it => it.DESC).Select(grp => new {DESC = grp.key, Count = grp.COUNT()}).OrderBy(x => x.DESC)
这给了我以下错误:- 无法将类型系统 linq iorderedqueryable 隐式转换为 system.collections.generic.ienumerable
一如既往地感谢您的帮助。