将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; } }