0

I have the following SQL query that has left join with tow parameters

select val1,val2 from  tbl1 
left join tbl2 on (tbl1.ID = tbl2.ForKey1 or tbl1.id= tbl2.ForKey2)

What is the equivalent Linq query to it that retrieve the same result ?

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
Raed Alsaleh
  • 1,581
  • 9
  • 27
  • 50

1 Answers1

0

You can use documented Collection selector references outer in a non-where case

var query = 
   from tbl1 in ctx.tbl1 
   from tbl2 in ctx.tbl2
      .Where(tb2 => tbl1.ID == tbl2.ForKey1 || tbl1.id == tbl2.ForKey2)  
      .DefaultIfEmpty()
   select new 
   {
      tbl1,
      tbl2
   };
Svyatoslav Danyliv
  • 21,911
  • 3
  • 16
  • 32