我有兩個類,Profile和Download。下載具有映射到配置文件中ID的外鍵ProfileID。下載中的每一行代表連接的配置文件的一個下載。Linq通過在另一個列表中出現外鍵來查詢命令列表
我在製作一個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);
你有什麼代碼已經準備好,我們可以有一看? – DDiVita
我將它添加到原始帖子中。 – granra