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;
});
using System.Linq;
var grpResult = pObj.GroupBy(o=> o.OrdersID);