Simple Examples of joining 2 and 3 table using lambda expression

前端 未结 3 1493
情书的邮戳
情书的邮戳 2020-12-25 11:34

Can anyone show me two simple examples of joining 2 and 3 tables using LAMBDA EXPRESSION(
for example using Northwind tables (Orders,CustomerID,EmployeeID)

3条回答
  •  温柔的废话
    2020-12-25 11:50

    Code for joining 3 tables is:

    var list = dc.Orders.
                    Join(dc.Order_Details,
                    o => o.OrderID, od => od.OrderID,
                    (o, od) => new
                    {
                        OrderID = o.OrderID,
                        OrderDate = o.OrderDate,
                        ShipName = o.ShipName,
                        Quantity = od.Quantity,
                        UnitPrice = od.UnitPrice,
                        ProductID = od.ProductID
                    }).Join(dc.Products,
                            a => a.ProductID, p => p.ProductID,
                            (a, p) => new
                            {
                                OrderID = a.OrderID,
                                OrderDate = a.OrderDate,
                                ShipName = a.ShipName,
                                Quantity = a.Quantity,
                                UnitPrice = a.UnitPrice,
                                ProductName = p.ProductName
                            });
    

    Thanks

提交回复
热议问题