Can anyone show me two simple examples of joining 2 and 3 tables using LAMBDA EXPRESSION(
for example using Northwind tables (Orders,CustomerID,EmployeeID)?
A lambda expression with an expression on the right side of the => operator is called an expression lambda. An expression lambda returns the result of the expression and takes the following basic form: C# Copy. (input-parameters) => expression. The body of an expression lambda can consist of a method call.
The '=>' is the lambda operator which is used in all lambda expressions. The Lambda expression is divided into two parts, the left side is the input and the right is the expression. The Lambda Expressions can be of two types: Expression Lambda: Consists of the input and the expression.
In Java 8, it is also possible for the body of a lambda expression to be a complex expression or statement, which means a lambda expression consisting of more than one line. In that case, the semicolons are necessary.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With