You must Sign In to post a response.
  • Category: LINQ

    Please provide solution, how can i select all fields in LINQ using join.

    from A in ABC
    join B in CBD on A.Country equals B.CountryID
    join C in SSL on A.SL_ID equals C.SID
    join D in CCA on A.CID equals D.CID
    join E in TAA on A.TAID equals E.TAID
    join F in RTN on A.RT equals F.RTID
    into alloc from rows in alloc
    where A.PropertyID=37 select new {ABC=A,CBD=rows}

    please tell me how can select all fields in LINQ using JOIN please suggest to me best solutions.

    please provide solution for multiple table join as i have more than 5 table and i want to implement or also using in our project.

    Thanks,

    Atul Sharma
  • #747946
    I have mentioned below two ways of doing it. You can use any of the below methods.

    First Method :
    var test = from A in lABC
    join B in lCBD on A.Country equals B.CountryID
    join C in lSSL on A.SL_ID equals C.SID
    join D in lCCA on A.CID equals D.CID
    join E in lTAA on A.TAID equals E.TAID
    join F in lRTN on A.RT equals F.RTID

    into alloc

    from rows in alloc
    where A.Country == 1
    select new { A, B, C, D, E, rows };
    foreach(var i in test)
    {
    Console.Write(i.A.CID + " " + i.A.Country + " " + i.B.CountryID + " " + i.C.SID + " " + i.D.CID + " " + i.E.TAID + " " + i.rows.RTID);
    Console.WriteLine();
    }

    Second Method :
    var test = from A in lABC
    join B in lCBD on A.Country equals B.CountryID
    join C in lSSL on A.SL_ID equals C.SID
    join D in lCCA on A.CID equals D.CID
    join E in lTAA on A.TAID equals E.TAID
    join F in lRTN on A.RT equals F.RTID

    into alloc

    from rows in alloc
    where A.Country == 1

    select new { ABC = A, CBD = B, SSL = C, CCA = D, TAA = E, CBD1 = rows };

    foreach(var i in test)
    {

    Console.Write(i.ABC.CID + " " + i.ABC.Country + " "+ i.CBD.CountryID + " " + i.SSL.SID + " "+ i.CCA.CID + " "+ i.TAA.TAID + " " + i.CBD1.RTID);
    Console.WriteLine();
    }

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #747982
    Concat is Equivalent of UNUION ALL in sql which will return all columns from both the tables,


    var Joinquery = (from ABC in db.Table1 select new {A = ABC.A, B = ABC.B})
    .Concat( from XYZ in db.Table2 select new {A = XYZ.A, B = XYZ.B} );





    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #748126
    refer this link.. hope it helps you

    http://blogs.msdn.com/b/charlie/archive/2007/02/20/one-to-many-and-joins.aspx

    regards
    Kush


  • Sign In to post your comments