我已经尝试/搜索了2天。我有这种对象类型。
public class QCProcessDetail
{
public DateTime CreatedDateUTC { get; set; }
public string CreatedByUser { get; set; }
public DateTime CompletedDateUTC { get; set; }
public string CompletedByUser { get; set; }
public string Location { get; set; }
}
public class QCProcessStages
{
public string SerialNumber { get; set; }
public ICollection<QCProcessDetail> QCProcessDetails { get; set; }
}
我正在尝试获取唯一的“ createdByUsers”计数。我可以使用从这里看到的各种示例来获取用户名,但结果显示为
CreateByUserX = 1;
CreatedByUserY = 1;
CreatedByUserX = 1; ...
我需要这样的结果
CreatedByUserX = 2
CreateByUserY = 1
答案 0 :(得分:1)
为您更新的示例数据相应地更新我的答案:
stages
.SelectMany(s => s.QCProcessDetails)
.GroupBy(d => d.CreatedByUser)
.ToList()
.ForEach(g => Console.WriteLine(g.Key + " = " + g.Count()));