LINQ按多个字段分组-语法帮助
以便按多列分组需要进行的更正是什么
var query = from cm in cust group cm by new { cm.Customer, cm.OrderDate } into cms
select
new
{ Key1 = cms.Key.Customer,Key2=cms.Key.OrderDate,Count=cms.Count() };
var qry = cust.GroupBy(p => p.Customer, q => q.OrderDate, (k1, k2, group) =>
new { Key1 = k1, Key2 = k2, Count = group.Count() });
回答:
在点表达式中使用与查询表达式中相同的匿名类型:
var qry = cust.GroupBy(cm => new { cm.Customer, cm.OrderDate }, (key, group) => new { Key1 = key.Customer, Key2 = key.OrderDate,
Count = group.Count() });
(在真正的IDE中,我将(key, group)
在该cm
参数下排队,但随后它将包裹在SO中。)
以上是 LINQ按多个字段分组-语法帮助 的全部内容, 来源链接: utcz.com/qa/426810.html