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<TKey, TElement>资料
https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/bb343251(v=vs.95)?WT.mc_id=DT-MVP-5003010
来源:https://www.cnblogs.com/Lulus/p/12602905.html