HOW TO JOIN MULTIPLE TABLE IN LINQ QUERY.

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
LINQ 
 581  View(s)
Ratings:
Rate this:
I want to join multiple table in linq query. how to do this please help me.
  1. Ankit Singh

    Post:341

    Points:2389
    Re: How to join multiple table in Linq Query.

    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
    };

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!