我有一个linq查询,我想对多列进行分组。
DataTable approvals = ds.Tables[0];
IEnumerable<DataRow> query =
from approval in approvals.AsEnumerable()
group approval by approval.Field<string>("TaskName") into grp
let MaxSubmissionDate = grp.Max(g => g.Field<DateTime>("SubmissionDate"))
from a in grp
where a.Field<DateTime>("SubmissionDate") == MaxSubmissionDate
select a;
// Create a table from the query.
DataTable resultTable = query.CopyToDataTable<DataRow>();
以上是单列,但是当我尝试如下添加另一列时,它不起作用。
IEnumerable<DataRow> query =
from approval in approvals.AsEnumerable()
group approval by { approval.Field<string>("DelegationName"), approval.Field<string>("TaskName")} into grp
let MaxSubmissionDate = grp.Max(g => g.Field<DateTime>("SubmissionDate"))
from a in grp
where a.Field<DateTime>("SubmissionDate") == MaxSubmissionDate
select a;
在大括号中,它抱怨“批准”在当前上下文中不存在。如何将多列分组?