聚合不同 ID 的 Linq

Linq that Aggregates distinct IDs

我无法针对以下问题获取正确的 Linq 查询: 我有一个包含以下数据的故事点列表<>:

ParentID    TaskID      Points
--------    ------    -----------
    1         100          2
    1         101          1
    1         103          1
    2         102          1
    2         104          4
    3         105          1

我正在寻找具有故事点总数的不同 ParentID 的列表:

ParentID    Count
--------    -----
   1          4
   2          5
   3          1

我试过这个块,但语法出错:

var storytaskpoints =
                        from u in storypoints
                        group u by u.ParentID into g
                        select new
                        {
                            ParentID = g.Key,
                            Count = (from u in g select u.Points).Count();
                        }

我的 Class 的 StoryTaskPoint:

class StoryTaskPoint
    {
        public int ParentID { get; set; }
        public int Points { get; set; }
        public int TaskID { get; set; }

        public StoryTaskPoint()
        { }

        StoryTaskPoint(
            int taskID,
            int parentID,
            int points)
        {
            TaskID = taskID;
            ParentID = parentID;
            Points = points;
        }
    }

如有任何帮助,我们将不胜感激....

 from u in storypoints
                        group u by u.ParentID into g
                        select new
                        {
                            ParentID = g.Key,
                            Count = g.Sum(gg=>gg.Points)
                        }

使用.Sum代替.Count