2014-01-20 49 views
0

我想結束一個列表,根據用戶標識對我的類別進行分組。你如何在你的SQL上使用Group Statement來Linq查詢?

 IEnumerable<JoinClass> catList = 
         from c in db.Users2 
         join e in db.Categories on c.Id_Users equals e.FK_Users 
         where c.EEID == UserEEID 
         group e.Category by c.EEID in z 
         select new JoinClass 
         { 
          Category = e.Category, 
          EEID = c.EEID, 
         }; 

     return View(catList.ToList()); 
+0

你不顯示JoinClass的定義。另外,這段代碼如何不適合你? – Hogan

回答

0
IEnumerable<JoinClass> catList = 
        from c in db.Users2 
        join e in db.Categories on c.Id_Users equals e.FK_Users 
        where c.EEID == UserEEID 
        group e.Category by c.EEID in z 
        select new JoinClass 
        { 
         Categories = z.ToList(), 
         EEID = z.Key, 
        }; 

    return View(catList.ToList()); 

假設你其實是要找到每個EEID所有類別。