本文介绍了选择计数LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到列的SQL Server表 ResolvedDate
和 ResolvedBy
。
现在我要选择那些两列和计算它们的结果,我想我会实现这样的:
_dataContext.Activities
。凡(A => a.IsResolved和放大器;&安培; a.ResolvedBy ==用户id)
。选择(A =>新建{a.ResolvedDate,*** COUNT ***});
正如你所看到的,计数部分缺失。
我想每一个活动,即在这ResolvedDate已经完成又算什么呢。
我怎么能实现呢?
解决方案
从在dataContext.Activities
其中,a.IsResolved和放大器;&安培; a.ResolvedBy ==用户id
一组由a.ResolvedDate为G
选择新{ResolvedOn = g.Key,NumberResolved = g.Count()}
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.
I want to get every activity, that has been done in this ResolvedDate and count it.
How can I implement that?
解决方案
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!