Resources » Code Snippets » Visual Studio

Linq join on multiple columns


Posted Date: 12-Mar-2010  Last Updated:   Category: Visual Studio    
Author: Member Level: Gold    Points: 10


How to perform join in Linq Concepts with multiple columns?



Simple join using Linq to SQL Have one columns id in both table



ar qry = from tmep in table1
join temp1 in table2
on {temp.ID} equals {temp1.ID}


have two columns id and country in both table


var qry = from tmep in table1
join temp1 in table2
on new {temp.ID,temp.Country} equals new {temp1.ID,temp2.Country}


how to join in multiple table ?


Select distinct MMC.ClmNoKey, MMC.CaseNoKey, SP.ApppointDt, SP.RefNo, MMC.ClmTypeCd, CT.ClmTypeGroupCd, CT.Dsc, SP.SpCd, MMC.CoUserCd, M.VehNo
from CmastOwnSP SP

join MCMastCase MMC on SP.ClmNoKey = MMC.ClmNoKey
join uClmType CT on MMC.ClmTypeCd = CT.ClmCaseTypeCdKey
join MCMast as M on M.ClmNoKey = SP.ClmNoKey
join CMast as CM on SP.ClmNokey = CM.ClmNokey

where spcd = 'MCSTKL' and Sp.AppointDt is not Null and Sp.AckDt is Null
and CT.ClmTypeGroupCd = Sp.ClmTypeCd and MMC.ClmCaseStatusCd <> ‘C’
and SP.DelInd = 0



related LINQ Query


var Query = from objSP in
(from SP in objClaimStatusDC.CMastOwnSPs
join MMC in objClaimStatusDC.MCMastCases on SP.ClmNoKey equals MMC.ClmNoKey
join CT in objClaimStatusDC.uClmTypes on MMC.ClmTypeCd equals CT.ClmCaseTypeCdKey
join M in objClaimStatusDC.MCMasts on SP.ClmNoKey equals M.ClmNoKey
join CM in objClaimStatusDC.CMasts on SP.ClmNoKey equals CM.ClmNoKey
where SP.SPCd == 'mcstkl' && SP.AppointDt != null && SP.AckDt == null && SP.DelInd == false && MMC.ClmCaseStatusCd != "C"

select new
{
MMC.ClmNoKey,
SP.AppointDt,
SP.RefNo,
MMC.COUserCd,
CT.Dsc,
CM.Ins,
M.VehNo,
MMC.CaseNoKey,
MMC.ClmTypeCd,
CT.ClmTypeGroupCd,
SP.SPCd,

}).ToList().Distinct()
select new
{
ClmNoKey = objSP.ClmNoKey ?? "",
AppointDt = objSP.AppointDt,
RefNo = objSP.RefNo,
CoUserCd = objSP.COUserCd,
Dsc = objSP.Dsc,
Ins = objSP.Ins,
VehNo = objSP.VehNo,
CaseNoKey = objSP.CaseNoKey,
ClmTypeCd = objSP.ClmTypeCd,
GroupCD = objSP.ClmTypeGroupCd,
SPCD = objSP.SPCd,

};


Did you like this resource? Share it with your friends and show your love!

Responses to "Linq join on multiple columns"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Pawan Awasthi
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India