使用 linq 和 sum 聚合列表
我正在尝试合并一个正在序列化的可枚举列表我
有如下所示的数据:
Internet explorer 10
Internet explorer 15
Mozille firefox 10
我
Internet explorer 25
Mozille firefox 10
我的类看起来像:
public class BrowserVisits
{
public string BrowserName { get; set; }
public int Visits { get; set; }
}
当前的序列化可枚举列表(r)的查询看起来像:
var browserVisits = from r in reportData
select new BrowserVisits
{
BrowserName = r.Dimensions.First(d => d.Key == Dimension.Browser).Value,
Visits = int.Parse(r.Metrics.First(d => d.Key == Metric.Visits).Value)
};
我该怎么办linq 中带有 sum 的 group by ?
我需要进行两次查询,还是可以进行一次查询。
如果这听起来含糊不清,我深表歉意,这是漫长的一天,但如果需要澄清,我非常乐意补充这一点
i am trying to consolidate an ienumerable list that i am serializing
i have data that looks like this:
Internet explorer 10
Internet explorer 15
Mozille firefox 10
I was it to look like:
Internet explorer 25
Mozille firefox 10
my class looks like:
public class BrowserVisits
{
public string BrowserName { get; set; }
public int Visits { get; set; }
}
my current query to serialize an ienumerable list (r) looks like:
var browserVisits = from r in reportData
select new BrowserVisits
{
BrowserName = r.Dimensions.First(d => d.Key == Dimension.Browser).Value,
Visits = int.Parse(r.Metrics.First(d => d.Key == Metric.Visits).Value)
};
how do i go a group by with sum in linq?
do i need to go two queries, or can i do a single one.
apologies if this sounds vague, its been a long day, but am more than happy to add to this if it needs clarification
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
怎么样:
这对我来说对你的样本数据有用。
What about:
This works for me against your sample data.
名称 价值
互联网浏览器sp; 10
互联网浏览器 15
Mozille firefox 10
Name Value
Internet explorer 10
Internet explorer 15
Mozille firefox 10