如何将以下sql查询转换为lambda表达式?
SELECT Username, COUNT(Username) AS Count
FROM user
GROUP BY Username
答案 0 :(得分:0)
var UserCount = yourEntityObject.GroupBy(m => m.Username)
.Select(c => new {Username = c.Key, Count = c.Count()});
答案 1 :(得分:0)
尝试以下方法:
var grpUsers = empList.GroupBy(user => user.Username)
.Select(lst => new {Username = lst.Key, Count = lst.Count()} );