我有两个课程,个人资料和下载。下载具有外键ProfileID,该外键映射到Profile中的ID。下载中的每一行代表所连接配置文件的一个下载。
我在执行linq查询时遇到麻烦,该查询可获取按下载次数排序的个人档案列表。
编辑:这是到目前为止我在函数中。
IndexViewModel model = new IndexViewModel();
model.NewSubtitles = (from Profile in _ProfileRepo.GetAll()
orderby Profile.ID descending
select Profile).Take(5).ToList();
// This doesn't work:
// model.TopSubtitles = (from n in _ProfileRepo.GetAll()
// join d in _DownloadRepo.GetAll() on n.ID equals d.ProfileID into c
// group c by c.ProfileID into g
// orderby g.Count() descending
// select n).Take(5).ToList();
return View(model);
试试这个 :
model.NewSubtitles = (from Profile in _ProfileRepo.GetAll()
join downloads in _DownloadRepo.GetAll() on Profile.UserId equals downloads.UserId
group downloads by Profile into p
orderby p.Count() descending
select new {p.Key.UserId , p.Key.UserName , p.Count()).Take(5).ToList();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句