首页 新闻 会员 周边 捐助

lambdda 如何使用groupby?

0
悬赏园豆:20 [待解决问题]
SqlDataReader reader = DbHelperSQL.RunProcedure("Pro_Fujet_Orders_SearchByCondition", param);

List
<Tuan.Model.New.OrdersInfo> orderList = new List<Tuan.Model.New.OrdersInfo>();
orderList
= Pan.Common.DataReader2List.ReaderToList<Tuan.Model.New.OrdersInfo>(reader, false);

reader.NextResult();
List
<Tuan.Model.OrderProducts> pObj = Pan.Common.DataReader2List.ReaderToList<Tuan.Model.OrderProducts>(reader, true);

orderList.ForEach(o
=>
{
o.OrderProducts
= pObj.Where(p => p.OrdersID == o.OrdersID).ToList();
o.Count
= o.OrderProducts.Count;
});

使用groupby ,如何改写下面的语句呢?觉得用foreach 效率有点低

orderList.ForEach(o =>
            {
                o.OrderProducts = pObj.Where(p => p.OrdersID == o.OrdersID).ToList();
                o.Count = o.OrderProducts.Count;
            });

FelixLoeng的主页 FelixLoeng | 菜鸟二级 | 园豆:244
提问于:2011-04-14 15:24
< >
分享
所有回答(1)
0

using System.Linq;

var grpResult = pObj.GroupBy(o=> o.OrdersID);

Launcher | 园豆:45050 (高人七级) | 2011-04-15 09:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册