如何解决如何计算不同
我正在实施ASP.NET Core项目,并具有如下查询以查找每个userId
的不同operatorName
的计数,但是它向我显示了运行项目后出现的不同行数的错误:
var activeUserPerOperatorCount = requests.GroupBy(x => new { operatorName = x.Operator.Name,x.UserId }).Select(x => new
{
userIds = x.Key.UserId,operatorNames = x.Key.operatorName,activeUserPerOperatorCount = x.Select(l => l.UserId).Distinct().Count()
}).ToList();
如果有人帮助我,如何在查询中为每个userId
查找不同数量的operatorName
,我将不胜感激。
解决方法
好的,正确的查询如下所示,并且可以正常工作:
var activeUserPerOperatorCount = requests.GroupBy(x => new { operatorName = x.Operator.Name}).Select(x => new
{
operatorNames = x.Key.operatorName,activeUserPerOperatorCount = requests.Select(l => l.UserId).Distinct().Count()
}).ToList();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。