Click here to Skip to main content
15,035,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please find the below linq query. Here it works as Inner Join but I need it as Left Join
Please help me in fixing this

from pd in IntegrationAudits join od in IntegrationStatus on pd.IntegrationStatusID equals od.IntegrationStatusId
join ct in IntegrationMasters on od.IntegrationMasterId equals ct.IntegrationMasterId
where ct.PackageName == "Export TF58361 and TF58362 and TF58363" &&
(pd.CreatedDate >= DateTime.Now && pd.CreatedDate <= DateTime.Now)
select new {
ct.IntegrationEntity,ct.PackageName,pd.ImportStart,pd.ImportEnd,pd.ImportStatus
}




Please help me I am new to this.
Posted

Check this out:

Joins With Linq[^]
   
Please find the modified version with the changes appearing in bold. Sorry I could not test it, please let me know if there is any issue with this.

C#
from pd in IntegrationAudits 

join od in IntegrationStatus on pd.IntegrationStatusID equals od.IntegrationStatusId into a1
join ct in IntegrationMasters on od.IntegrationMasterId equals ct.IntegrationMasterId into b1

where ct.PackageName == "Export TF58361 and TF58362 and TF58363" &&
(pd.CreatedDate >= DateTime.Now && pd.CreatedDate <= DateTime.Now)

from od in a1.DefaultIfEmpty()
from ct in b1.DefaultIfEmpty()
select new {
ct.IntegrationEntity,ct.PackageName,pd.ImportStart,pd.ImportEnd,pd.ImportStatus
}
   
Comments
Member 10505512 9-Apr-14 0:51am
   
from pd in IntegrationAudits

join od in IntegrationStatus on pd.IntegrationStatusID equals od.IntegrationStatusId into a1
join ct in IntegrationMasters on od.IntegrationMasterId equals ct.IntegrationMasterId into b1

where ct.PackageName == "Export TF58361 and TF58362 and TF58363" &&
(pd.CreatedDate >= DateTime.Now && pd.CreatedDate <= DateTime.Now)

from od in a1.DefaultIfEmpty()
from ct in b1.DefaultIfEmpty()
select new {
ct.IntegrationEntity,ct.PackageName,pd.ImportStart,pd.ImportEnd,pd.ImportStatus
}

Here in od.IntegrationMasterId it is raising the below error :
join ct in IntegrationMasters on od.IntegrationMasterId equals ct.IntegrationMasterId into b1
ERROR:
Cannot execute text selection: The name 'od' is not in scope on the left side of 'equals'. Consider swapping the expressions on either side of 'equals'.
Member 10505512 9-Apr-14 3:10am
   
Solved.. Thanks for the Reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900