GroupBy使用linq方法语法(不是查询语法) [英] GroupBy with linq method syntax (not query syntax)

查看:82
本文介绍了GroupBy使用linq方法语法(不是查询语法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用扩展方法语法,以下查询将如何显示?

How would the following query look if I was using the extension method syntax?

var query = from c in checks
group c by string.Format("{0} - {1}", c.CustomerId, c.CustomerName) 
into customerGroups
select new { Customer = customerGroups.Key, Payments = customerGroups }

推荐答案

它看起来像这样:

var query = checks
    .GroupBy(c => string.Format("{0} - {1}", c.CustomerId, c.CustomerName))
    .Select (g => new { Customer = g.Key, Payments = g });

这篇关于GroupBy使用linq方法语法(不是查询语法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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