Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to crate a LINQ query which has two left join condition.

SQL
For Example:

Select BillMain.ID, BillMain.AccountID, BillMain.ItemID from BillMain Left Join BillSub ON BillMain.Ref = BillSub.Ref AND BillMain.Billing = BillSub.Billing


What will be query for LINQ?
Posted

Try this
C#
var result=from a in BillMain
join b in BillSub on new{a.Ref,a.Billing} equals {b.Ref,b.Billing} into res
from r in res.DefaultIfEmpty()
select new {ID=a.ID,AccountID=a.AccountID,ItemID=a.ItemID};
 
Share this answer
 
v2
Have a look here: http://smehrozalam.wordpress.com/2010/04/13/linq-how-to-write-queries-with-complex-join-conditions/[^].
The idea is creating an anonymous object with the two fields on both sides, and checking their equality.
 
Share this answer
 

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