我不确定如何使用实体框架执行此操作。我得到了以下内容:
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次出现的记录。
答案 0 :(得分: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();
答案 1 :(得分: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#中更具惯用性。)