[英]How can i Join, GroupBy and Select with LINQ?
I am trying to perform Join, GroupBy two columns and select to a new list as我正在尝试将 Join、GroupBy 两列和 select 执行到一个新列表中
var v = master.Join(
detail,
o => o.Id,
d => d.OrderId,
(o, d) => new
{
DateAdded = o.DateAdded,
VatRate = d.VatRatePercentage,
InvoiceDescription = o.InvoiceDescription
}).GroupBy(c => new
{
c.DateAdded,
c.VatRate
})
.Select(gcs => new
{
DateAdded = gcs.Key.DateAdded.Date,
VatRate = gcs.Key.VatRate,
InvoiceTypeDescription = gcs.Key.InvoiceDescription,
}
).ToList();
but i get the error但我得到了错误
'<anonymous type: DateTime DateAdded, decimal VatRate>' does not contain a definition for 'InvoiceTypeDescription' and no accessible extension method 'InvoiceTypeDescription' accepting a first argument of type '<anonymous type: DateTime DateAdded, decimal VatRate>' could be found
I would like to group by two columns (DateAdded, VatRate) but get the InvoiceDescription column also in the results.我想按两列(DateAdded,VatRate)分组,但在结果中也得到 InvoiceDescription 列。 How can i fix that?我该如何解决?
This is a sample:这是一个示例:
var resultmutiplekeylambaorderbyelement = studentlist
.GroupBy(stu => new{stu.standard, stu.age})
.OrderBy(g => g.Key.standard).ThenBy(y=> y.Key.age)
.Select(g => new { standardkey = g.Key.standard, agekey = g.Key.age, studentobj = g.OrderBy(y => y.name) });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.