2

我不确定如何使用实体框架来做到这一点。我得到以下信息:

return this.enrollments
                .Where(e => e.em_enrolled == false && e.em_result < _settings.PassMark)
                .GroupBy(e => e.em_subject_id)
                .Select(e => e.em_subject_id)
                .ToList();

我如何只检索存在 x 次的记录。

4

2 回答 2

7

您是指包含 x 个或更多项目的组吗?

return this.enrollments
                .Where(e => e.em_enrolled == false && e.em_result < _settings.PassMark)
                .GroupBy(e => e.em_subject_id)
                .Where(g => g.Count() >= x)
                .Select(g => g.Key)
                .ToList();
于 2013-05-23T04:15:40.957 回答
7

我怀疑你想要:

return this.enrollments
           .Where(e => !e.em_enrolled && e.em_result < _settings.PassMark)
           .GroupBy(e => e.em_subject_id)
           .Where(g => g.Count() >= x)
           .Select(g => g.Key)
           .ToList();

请注意,我已更改Select部分以反映您要从组中提取组密钥的事实。(我也避免与false, 更改e.em_enrolled == false为进行比较!e.em_enrolled。它们的意思当然是一样的,但我发现后者在 C# 中更惯用。)

于 2013-05-23T04:15:45.833 回答