如何按左(列)和左(列)编写linq组
本文关键字:linq 编写 和左 何按左 | 更新日期: 2023-09-27 18:31:29
我在SQL中有这个查询
SELECT DISTINCT '20' + Left(charWeekNo ,2) AS title, COUNT('') AS colspan
FROM Table1 PWeek
GROUP BY Left(charWeekNo ,2)
如何使用上面的查询在linq中编写?
var PWeek = Table1
.GroupBy(x=>x.charWeekNo.Substring(0,2))
.Select(x=>new{title = "20" + x.Key, colspan = x.Count()})
var result =Table1.GroupBy(x=>x.charWeekNo.Substring(0,2))
.Select(g=>new {title = "20" +g.Key, colspan =g.Count()}).ToList()