I have SQL Query
SELECT project_id,count(project_id) as vote_count from Votesgroup by project_id;
我如何使用 LINQ 编写此内容?我的 LINQ 起始代码:
private int GetCountOfVotes()
{
using (var db = new SafetyFundDbContext(Options))
{
return db.Votes.Select()
}
}
对不起,是的,我知道这个问题太愚蠢了,但我新手:D.
不要投票并标记为正确答案。
foreach(var vote in db.Votes.GroupBy(vot => vot.project_id)
.Select(group => new {
ProjectID = group.Key,
Count = group.Count()
})
.OrderBy(x => x.ProjectID)
{
Console.WriteLine("{0} : {1}", vote.ProjectID, vote.Count);
}