Home > DeveloperSection > Forums > How to join multiple table in Linq Query.
Ankit Singh

Total Post:341

Points:2389
Posted on    February-14-2016 10:25 PM

 LINQ LINQ 
Ratings:


 1 Reply(s)
 309  View(s)
Rate this:
I want to join multiple table in linq query. how to do this please help me.


Ankit Singh

Total Post:341

Points:2389
Posted on    February-14-2016 10:32 PM

we are write here two  type join multiple table in linq query.
1. 
var Result1 = db.CUSTOMER.Join(
db.ORDER,
cust => cust.CUST_ID,
ord => ord.CUST_ID,
(cust, ord) => new
{
cust,
ord
})
.Join(db.PRODUCT,
pro => pro.ord.PRODUCT_ID,
p => p.PRODUCT_ID,
(pro, p) => new { pro, p })
.Select(m => new
{
CustomerName = m.pro.cust.CUST_NAME,
OrdDate = m.pro.ord.ORD_DATE,
ProductName = m.p.PRODUCT_NAME
});
2.
var Result2 = from c in db.CUSTOMER
join o in db.ORDER on c.CUST_ID equals o.CUST_ID
join p in db.PRODUCT on o.PRODUCT_ID equals p.PRODUCT_ID
select new
{
CustomerName = c.CUST_NAME,
OrdDate = o.ORD_DATE,
ProductName = p.PRODUCT_NAME
};

Don't want to miss updates? Please click the below button!

Follow MindStick