2014-02-14 59 views
-5

listProducts我有一個名爲「家庭」的字段。我想要GroupBy這個字段。如何在LINQ中使用GroupBy?

var products = from listProducts in repository.All() 
       where (listProducts.Code == "48654") 
       select listProducts;` 
+3

你可以谷歌你自己的標題,立即獲取答案。 – ken2k

+0

這是重複的,請參閱http://stackoverflow.com/questions/13452161/linq-and-groupby和http://stackoverflow.com/questions/12887644/linq-how-to-do-groupby –

回答

0

試試這個,

var products = from listProducts in repository.All() 
       where listProducts.Code == "48654" 
       group listProducts by listProducts.family into grp 
       select grp; 

欲瞭解更多信息,請訪問LINQ Group By