list列转换为数组。linq的union与group by


  string[] cateIDs={} ;  
List<AMS_asset_categories> itemLst = IListHelper.IListToList<AMS_asset_categories>(lst).FindAll(t => t.parent_warehouse_id == warehouse.warehouse_id);
                                            if (itemLst.Count > 0)
                                            {
                                                string[] strstr = new string[itemLst.Count];
                                                strstr = itemLst.Select(c => c.category_id).ToArray();//选取list中的一列,赋值给数组
                                                cateIDs = strstr;
                                            }


2.linq的union与group by

 var query2 = from t in
                                             ((from p in context.AMS_Plan_Item
                                               join p1 in context.AMS_Plans on p.plan_id equals p1.plan_id into pAndP1
                                               from LFPAndP1 in pAndP1.DefaultIfEmpty()
                                               where p.plan_type == 1 && LFPAndP1.year == year && LFPAndP1.month == month
                                               select new
                                               {
                                                   plan_item_id = p.plan_item_id,
                                                   plan_id = p.plan_id,
                                                   asset_id = p.asset_id,
                                                   department_id = p.department_id,
                                                   plan_type = p.plan_type,
                                                   amount = p.amount,
                                                   audit_status = p.audit_status,
                                                   audit_description = p.audit_description,
                                                   reason = p.reason,
                                                   username = p.username,
                                                   backname = p.backname,
                                                   create_date = p.create_date,
                                                   back_date = p.back_date,
                                                   totalprice = p.totalprice,
                                                   SortCode = p.SortCode,
                                               }
                                                 ).Union(from p in context.AMS_Plan_Item
                                                         join p1 in context.AMS_Plans on p.plan_id equals p1.plan_id into pAndP1
                                                         from LFPAndP1 in pAndP1.DefaultIfEmpty()
                                                         where p.plan_type == 0 && LFPAndP1.year == year && LFPAndP1.month == month1
                                                         select new
                                                         {
                                                             plan_item_id = p.plan_item_id,
                                                             plan_id = p.plan_id,
                                                             asset_id = p.asset_id,
                                                             department_id = p.department_id,
                                                             plan_type = p.plan_type,
                                                             amount = p.amount,
                                                             audit_status = p.audit_status,
                                                             audit_description = p.audit_description,
                                                             reason = p.reason,
                                                             username = p.username,
                                                             backname = p.backname,
                                                             create_date = p.create_date,
                                                             back_date = p.back_date,
                                                             totalprice = p.totalprice,
                                                             SortCode = p.SortCode,
                                                         })).DefaultIfEmpty()
                                         join a in context.AMS_assets on t.asset_id equals a.asset_id into tAndA
                                         from LFTAndA in tAndA.DefaultIfEmpty()
                                         join u in context.AMS_units on LFTAndA.unit_id equals u.unit_id into aAndU
                                         from LFAAndU in aAndU.DefaultIfEmpty()
                                         join m in context.AMS_manufacturers on LFTAndA.manufacturer_id equals m.manufacturer_id into aAndM
                                         from LFAAndM in aAndM.DefaultIfEmpty()
                                         join b in context.AMS_brands on LFTAndA.brand_id equals b.brand_id into aAndB
                                         from LFAAndB in aAndB.DefaultIfEmpty()
                                         join p in context.AMS_Plans on t.plan_id equals p.plan_id into tAndP
                                         from LFTAndP in tAndP.DefaultIfEmpty()
                                         join cate in context.AMS_asset_categories on LFTAndA.category_id equals cate.category_id into aAndCate
                                         from LFAAndCate in aAndCate.DefaultIfEmpty()
                                         join ware in context.AMS_warehouses on LFAAndCate.parent_warehouse_id equals ware.warehouse_id into cateAndWare
                                         from LFCateAndWare in cateAndWare.DefaultIfEmpty()
                                         group t by new {LFTAndA.spinyin,LFTAndA.lpinyin, categoryid=LFAAndCate.category_id,categoryname=LFAAndCate.name, AssertName = LFTAndA.name, AssetId = t.asset_id, LFTAndA.alias, LFTAndA.price, LFTAndA.spec,  unitname = LFAAndU.name, manuname = LFAAndM.name, brandname = LFAAndB.name } into gs
                                         select new AMS_Plan_ItemView
                                         {
                                             category_id=gs.Key.categoryid,
                                             categoryname=gs.Key.categoryname,
                                             AssetId = gs.Key.AssetId,
                                             AssertName = gs.Key.AssertName,
                                             alias = gs.Key.alias,
                                             price = gs.Key.price,
                                             spec = gs.Key.spec,
                                             Amount = gs.Sum(c => c.amount),
                                             totalprice = gs.Sum(c => c.totalprice),
                                             lpinyin = gs.Key.lpinyin,
                                             spinyin = gs.Key.spinyin,
                                             unitname = gs.Key.unitname,
                                             manuname = gs.Key.manuname,
                                             brandname = gs.Key.brandname,
                                         };



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值