Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我如何使用LINQ来总结这些数据——按关系数分组的关系数_C#_.net_Linq_Linq To Sql - Fatal编程技术网

C# 我如何使用LINQ来总结这些数据——按关系数分组的关系数

C# 我如何使用LINQ来总结这些数据——按关系数分组的关系数,c#,.net,linq,linq-to-sql,C#,.net,Linq,Linq To Sql,我有一张简单的桌子,像: | fkId | Item | --------------- | 1 | A | | 1 | B | | 1 | C | | 1 | D | | 2 | H | | 2 | I | | 3 | Y | | 3 | Z | 您使用.GroupBy完成了一半-现在您必须应用另一个.GroupBy来完成其余操作: MyTable.GroupBy(i => i.FkID)

我有一张简单的桌子,像:

| fkId | Item | --------------- | 1 | A | | 1 | B | | 1 | C | | 1 | D | | 2 | H | | 2 | I | | 3 | Y | | 3 | Z |
您使用
.GroupBy
完成了一半-现在您必须应用另一个
.GroupBy
来完成其余操作:

MyTable.GroupBy(i => i.FkID)
       .GroupBy(group => group.Count())
       .Select(group => new { ItemCount = group.Key,
                              FkIdsWithItemCount = group.Count() });
MyTable
    .GroupBy(i => i.FkID)
    .Select(i => i.Count())
MyTable.GroupBy(i => i.FkID)
       .GroupBy(group => group.Count())
       .Select(group => new { ItemCount = group.Key,
                              FkIdsWithItemCount = group.Count() });