我有桌子
id pagenane username
我想要这个SQL查询
选择pagename,count(*)为pagestat中的num,其中username ='name'group by pagename
我怎么能用linq做到这一点?
答案 0 :(得分:2)
好吧,试试这个:
var query = from row in context.pageStat
where row.UserName == "name"
group row by row.PageName into g
select new { PageName = g.Key, Count = g.Count() };
答案 1 :(得分:0)
var retVal = (from s in dataContext.YourTable where
s.UserName.Equals("name")
group s by s.PageName into k
select new {PageName = k.Key, Count = k.Count() }).ToList();