Linq备忘
有些用法老是记不住,现在记录在网上,下次就容易查到了,不必到处搜索了。
1、Groupby
var tempPlanGoodsItems =
(from p in m_StockInPlan.GoodsItems
group p by new { p.GoodsName, p.MaterialNo, p.CompanySerialNo, p.SpecAndModel, p.BatchNo, p.SkuNo } into g
select new RestGoodsItem
{
GoodsName = g.Key.GoodsName,
MaterialNo = g.Key.MaterialNo,
CompanySerialNo = g.Key.CompanySerialNo,
SpecAndModel = g.Key.SpecAndModel,
BatchNo = g.Key.BatchNo,
SkuNo = g.Key.SkuNo,
PlanQuantity = g.Sum<PlanGoodsItem>(p => p.Quantity),
Quantity = 0,
}).ToList<RestGoodsItem>();
2、主子表查询(子表条件)
IList<StockOutPlan> stockOutPlans = m_StockOutPlanBizService.CreateQueryNoNoLazies("select distinct p from StockOutPlan as p inner join p.GoodsItems as g where g.StockInPlanNo='" + m_StockInPlan.PlanNo + "'", new List<string> { StockOutPlan.NON_LAZY_GOODSITEMS});