Linq join on multiple columns


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,

};


Comments

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