【发布时间】:2020-03-09 23:11:19
【问题描述】:
我需要一个 linq 查询方面的帮助,这让我发疯了。 我有一个包含以下数据的数据表:
Item1 / child1 / 10 列
Item1 / child2 / 10 列
Item2 / child1 / 10 列
Item3 / child1 / 10 列
Item3 / child2 / 10 列
我想要以下结果:
Item1 / 子项数 / child1 / 1 列
Item1 / 子项数 / child2 / 1 列
Item2 / 子项计数 / child1 / 1 列 等等....
在我的查询中,item 是“artiste”,child 是“album”,1 列是“disque”
var tre_res = from res in Globals.ds.Tables[0].AsEnumerable()
orderby res.Field<string>("artiste")
group res by new { arti = res.Field<string>("artiste"), alb = res.Field<string>("album") } into groupings
select new artisteYalbum { artiste = groupings.Key.arti, album = groupings.Key.alb, countealb = groupings.Count() };
我有 2 个问题:我无法理解计数的结果,这不是孩子的数量……另外,我不知道如何选择附加列。
这是artisteYalbum 类:
public class artisteYalbum
{
public string artiste { get; set; }
public string album { get; set; }
public string disque { get; set; }
public int countealb { get; set; }
}
最终,我希望能够填充树视图并将专辑数量(计数)放在艺术家姓名的末尾(带括号)。此查询将允许我立即输入该计数,而无需计算任何内容。 谢谢
【问题讨论】: