获取所有超过 5 个学生的评分教室

Get all scored classrooms with more than 5 students

我一直在尝试针对特定情况提出 Linq。我不想使用我客户数据库的名称 table,所以我已将情况转换为典型的 class 房间设置。

一个class房间有多名学生,甚至没有学生。 每个 class 可能会或可能不会被分配平均成绩。不用担心成绩从哪里来或者为什么它与 class.

分离

使用 Linq,我想获取所有 class 超过 5 名学生并且已指定平均成绩的房间。

对象看起来像这样。

class Classrooms {
    Guid ClassroomId;
    string subject;
}

class Students {
    Guid Student;
    Guid ClassroomId;
}

class Score {
    Guid ClassroomId;
    int someScoreHere;
}

在 SQL 我寻找这样的东西:

SELECT COUNT(*) As NumberOfStudents, ClassroomId 
FROM Students WHERE ClassroomId IN (SELECT ClassroomId FROM Score)
GROUP BY ClassroomId HAVING COUNT(StudentId) > 5 BY NumberOfStudents;

我在 Linq 尝试获取教室列表时失败了;

Guid[] scores = (from score in db.Score select score.ClassroomId).ToArray();
List<Classroom> result = (from c in db.Classroom
                        where db.Student.Contains(c.ClassroomId))
                        group c by c.ClassroomId.... BLEEEH
from c in db.Classroom
where db.Score.Select(s => s.ClassroomId).Contains(c.ClassroomId)
group c by c.ClassroomId into g
where g.Count() > 5
select new { NumberOfStudents = g.Count(), ClassroomId = g.Key }