Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Examples of joining 2 and 3 table using lambda expression

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

like image 287
Arian Avatar asked Apr 30 '11 05:04

Arian


People also ask

What is lambda expression in c3?

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.

Which operator is used in lambda expression?

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.

Can Lambda have more than one statement?

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.


1 Answers

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

like image 174
Arian Avatar answered Oct 05 '22 07:10

Arian