在 LINQ 中选择计数 [英] Selecting count in LINQ

查看:30
本文介绍了在 LINQ 中选择计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个包含 ResolvedDateResolvedBy 列的 SQL Server 表.

I got a SQL Server table with columns ResolvedDate and ResolvedBy.

现在我想选择这两列并计算它们的结果,我想我会这样实现:

Now I want to select those two columns and count their results, which I thought I'd implement like that:

_dataContext.Activities
    .Where(a => a.IsResolved && a.ResolvedBy == userId)
    .Select(a => new { a.ResolvedDate, ***COUNT*** });

如您所见,缺少计数部分.

As you can see, the Count-Part is missing.

我想获取在此 ResolvedDate 中完成的所有活动并对其进行计数.

I want to get every activity, that has been done in this ResolvedDate and count it.

我该如何实施?

推荐答案

from a in dataContext.Activities
where a.IsResolved && a.ResolvedBy == userId
group a by a.ResolvedDate into g
select new {ResolvedOn=g.Key, NumberResolved= g.Count()}

这篇关于在 LINQ 中选择计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆