Linq中关于Distinct关键字的问题 [英] Problems with Distinct keyword in Linq
本文介绍了Linq中关于Distinct关键字的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello All
我正在尝试将SQL查询更改为Linq查询,但我的语法有问题。
查询如下。它的目的是汇总每个唯一目的地的所有统计数据,它在SQL中需要它的工作原理
Hello All
I am trying to change a SQL query to Linq query but i have trouble with the syntax.
Query is as below. Its purpose is to sum all statistics for each unique destination and it works as i needed in SQL
选择 < font style ="font-size:11px"> distinct destination, sum (已回答) as 已回答, |
sum (siezed) as 已占用, sum (保持时间) as 保持时间, |
sum (totalduration) as 持续时间 来自 < font style ="font-size:11px"> report_test(nolock) group by destination |
select distinct destination ,sum(answered) as Answered, |
sum(siezed) as Seized,sum(holdtime) as Holdtime, |
sum(totalduration) as Duration from report_test(nolock) group by destination |
推荐答案
这类似的工作:
报告
.Groupby(r => r.Destination)
。选择(g => new {Destination = g.Key,Answered = g.Sum(u => u.Answered),...}
.Distinct(); < br>
希望这有帮助,
Sushil。
Would something like this work:
Reports
.Groupby (r => r.Destination)
.Select(g => new {Destination = g.Key, Answered = g.Sum(u => u.Answered), ...}
.Distinct();
Hope this helps,
Sushil.
这篇关于Linq中关于Distinct关键字的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文