class Program { public class Order { public int ID { get; set; } public string OrderNo { get; set; } } public class OrderDetail { public int ID { get; set; } public int OrderID { get; set; } public int ProductId { get; set; } } public class Product { public int ID { get; set; } public string Images { get; set; } } static void Main(string[] args) { //SendSMS(); //Charge(); var orderList = new List<Order>() { new Order(){ ID=1 ,OrderNo = "aaa"}, new Order(){ ID=2 ,OrderNo = "bbb"} }; var orderdetaillist = new List<OrderDetail>(){ new OrderDetail(){ ID=1, OrderID=1, ProductId = 1}, new OrderDetail(){ ID=2, OrderID=1, ProductId = 3}, new OrderDetail(){ ID=3, OrderID=1, ProductId = 4}, new OrderDetail(){ ID=4, OrderID=2, ProductId = 2}, new OrderDetail(){ ID=5, OrderID=2, ProductId = 5}, }; var productList = new List<Product>(){ new Product(){ ID=1,Images = "111"}, new Product(){ ID=2,Images = "222"}, new Product(){ ID=3,Images = "333"}, new Product(){ ID=4,Images = "444"}, new Product(){ ID=5,Images = "555"} }; var list = (from order in orderList join yo in (from d in orderdetaillist join p in productList on d.ProductId equals p.ID select new { d.OrderID, p.Images }) on order.ID equals yo.OrderID into gg select new { order.OrderNo, Images = (from fuck in gg select fuck.Images).ToList() }).ToList(); foreach (var item in list) { Console.WriteLine("订单号:" + item.OrderNo); Console.WriteLine("产品图片:"); foreach (var pic in item.Images) { Console.WriteLine(" " + pic); } Console.WriteLine(); } Console.ReadKey(); }
效果如下:
时间: 2024-12-13 09:54:24