我有以下linq表达式从我的数据库中提取所有数据:
var items = response.Select(a => a.SessionLocationID).ToArray();
mdl = _meetingRepository.Select<SessionLocation>()
.OrderBy(a => a.SessionDT).ThenBy(a => a.SessionEndTime);
现在我想按实际实时字段分组,只有实际房间数&gt; 3
这可能吗?
答案 0 :(得分:6)
您可以使用GroupBy
,请记住您正在丢失已经完成的排序,所以我会在您进行排序之前开始:
var groups = _meetingRepository.Select<SessionLocation>()
.GroupBy(x => x.ActualRoom)
.Where(g => g.Count() > 3)
要排序组 - 假设将计数保留为单独的属性不是必需的,您只需投射到IEnumerable
IEnumerable<SessionLocation>
:
var groups = _meetingRepository.Select<SessionLocation>()
.GroupBy(x => x.ActualRoom)
.Where(g => g.Count() > 3)
.Select(g => g.OrderBy(x => x.SessionDT).ThenBy(x => x.SessionEndTime));