2012年7月26日 星期四

{Linq} LINQ Group 群組加總資料

//Group PN欄位,總計Instock欄位內數量

   var Inventory = (from inv in context.InventoryDatas.ToList()
                                    group inv by inv.PN
                                        into gropData
                                        select new
                                        {
                                            PN = gropData.Key,
                                            Instock = gropData.Sum(s => s.Instock),
                                        }).ToList();


參考資料:
http://www.dotblogs.com.tw/chhuang/archive/2008/05/01/3772.aspx