如何在LINQ中使用GroupBy?

时间:2014-02-14 16:34:31

标签: c# asp.net-mvc linq entity-framework

listProducts我有一个名为“家庭”的字段。我想GroupBy这个领域。

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

1 个答案:

答案 0 :(得分:0)

试试这个,

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

有关详细信息,请访问LINQ Group By