C#-LINQ

 

将list看做是数据库中的表,LINQ 的lamba表达式相当于SQL,对对象实行查询。

 

 

            using (var ef = new SDS_NONEDIEntities3())
            {
                var header = ef.Shipment_Header.ToList<Shipment_Header>();
                var item = ef.Shipment_Item.ToList<Shipment_Item>();
                var rst = header.Join(item, h =>new { h.ShipmentNo, h.CustomerID}, i => new { i.ShipmentNo, i.CustomerID }, (h, i) => new { CustomerID = h.CustomerID, Status = h.Status, ShipmentNo = h.ShipmentNo, DN = i.DeliveryNo })
                               .Where(s => s.CustomerID == "aaa" && s.Status == "4")
                               .Select(s => new { SI = s.ShipmentNo, Customerid = s.CustomerID, DN = s.DN })
                               .OrderBy(s => s.SI)

                               ;
                foreach (var ss in rst)
                {
                    var xx = ss.SI;
                }
            }

 

C#-LINQ

上一篇:C# 如何实现完整的INI文件读写类


下一篇:【MS SQL】数据库维护计划之数据库备份(一)