var items = _voteRecordRepository.GetAll() .Where(x => programIds.Contains(x.ProgrammeId)) .GroupBy(x=>new {x.ClientType,x.ProgrammeId}) .Select((group)=>new ProgramVoteRecordSelectItem() { ProgramId = group.Key.ProgrammeId, GetVote=group.Count(), ClientType=group.Key.ClientType, //这里group是一个集合,如果要取某条记录的信息需要先查找实体,比如: DishName=group.FirstOrDefault()!=null?group.FirstOrDefault().DishName:"", NameList= group.ToList().Select(x=>x.Name).ToList(), }) .ToList();
IGrouping