程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> 二段Linq Groupby操作,二段linqgroupby

二段Linq Groupby操作,二段linqgroupby

編輯:關於.NET

二段Linq Groupby操作,二段linqgroupby


var messages = list.GroupBy(p=>p.RefOrderNo,(k,v)=> new {OrderNo = k,SkuInfo = v})
                    .Select(p =>
                    {
                        var item = p.SkuInfo.FirstOrDefault();
                        return new ReplaceLabelSkuMessage
                        {
                            OrderNo = p.OrderNo,
                            Operation = new WMS.Message.Operation
                            {
                                Operator = item.CreateBy,
                                OperateTime = item.CreateOn
                            },
                            ReplaceLabelSkuDetail = p.SkuInfo.Select(s => new ReplaceLabelSkuDetail
                            {
                                SKU = s.SKU,
                                Weight = s.Weight,
                                Lenght = s.Lenght,
                                Width = s.Width,
                                Height = s.Height
                            }).ToList()
                        };                        
                    });
var request = deliveryList.GroupBy(g => g.DeliveryNo)
                    .Select(delivery =>
                    {
                        var item = delivery.FirstOrDefault();
                        var yewuRequest = new DeliveryTicketShipOutMessage
                        {
                            DeliveryTicketNo = item.DeliveryNo,
                            DeliveryType = TMS.Message.DeliveryTicket.DeliveryType.Logistics,
                            WarehouseCode = item.YewuWarehouseCode,
                            ShipOutWarehouse = item.YewuWarehouseCode,

                            SkuContainers = delivery.GroupBy(g => g.ContainerCode).Select(container =>
                            {
                                var containerLine = container.FirstOrDefault();
                                return new LogisticsDeliveryShipOutCustomerAsnContainerRequest
                                {
                                    ContainerId = containerLine.ContainerCode,
                                    customerOrderType = TMS.Message.Common.CutomerOrderType.First,
                                    TargetWarehouseCode = containerLine.TargetWarehouseCode,
                                    CustomerAsnId = containerLine.CustomerAsnId,
                                    PalletId = containerLine.PalletId,
                                    Weight = new Weight { Value = containerLine.Weight, Unit = WeightUnit.G },
                                    Size = new Packing() { Length = containerLine.Length, Width = containerLine.Width, Height = containerLine.Height, Unit = LengthUnit.CM },

                                    Lines = container.GroupBy(l => l.SKU).Select(line =>
                                    {
                                        return new LogisticsDeliveryShipOutCustomerAsnContainerLineRequest
                                        {
                                            SKU = line.Key,
                                            Quantity = line.Sum(s => s.PackingQty),
                                            AccountNo = line.FirstOrDefault().CustomerCode
                                        };
                                    }).ToList(),

                                    Bags = container.Where(p => p.BagCode.Length > 0).GroupBy(g => g.BagCode).Select(bag =>
                                    {
                                        var bagid = bag.Key;
                                        return new LogisticsDeliveryShipOutCustomerAsnContainerBagRequest
                                        {
                                            BagId = bagid,
                                            Lines = bag.Select(bagline => new LogisticsDeliveryShipOutCustomerAsnContainerBagLineRequest
                                            {
                                                SKU = bagline.SKU,
                                                Quantity = bagline.PackingQty,
                                                AccountNo = bag.FirstOrDefault().CustomerCode
                                            }).ToList()
                                        };
                                    }).ToList()
                                };
                            }).ToList(),
                            OperateBy = item.CreateBy,
                            OperateOn = item.CreateOn
                        };

                        return yewuRequest;
                    }).ToList();

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved