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)?

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


try this one to join 2 tables using lambda expression

var list = dataModel.Customers                     
.Join( dataModel.Orders, 
      c => c.Id, 
      o => o.CustomerId, 
      (c, o) => new
                 {
                     CustomerId = c.Id, 
                     CustomerFirstName = c.Firstname, 
                    OrderNumber = o.Number
                 });

public void Linq102() 
{ 

string[] categories = new string[]{  
    "Beverages",   
    "Condiments",   
    "Vegetables",   
    "Dairy Products",   
    "Seafood" };  

List<Product> products = GetProductList(); 

var q = 
    from c in categories 
    join p in products on c equals p.Category 
    select new { Category = c, p.ProductName }; 

foreach (var v in q) 
{ 
    Console.WriteLine(v.ProductName + ": " + v.Category);  
} 
}

Need Your Help

How can I import data from ASCII (ISO/IEC 8859-1) to my Rails/PGSQL database?

mysql ruby-on-rails postgresql ruby-on-rails-4 import

I am trying to use data from the USDA found here: http://www.ars.usda.gov/Services/docs.htm?docid=23634