1

I have a sql having left outer join, I want to convert it to linq. the sql is

Select P.Surname, P.Othername H.history
from customers P left outer join historyfiles H on H.patID = P.patId 
     and H.category1 = 4 
where P.id = 2299

Thank you very much.

peter
  • 1,009
  • 3
  • 15
  • 23

1 Answers1

1

You can try this:

var query = from p in db.customers.Where(t => t.id == 2299 )
            join h in db.historyfiles.Where(l => l.category1 == 4 ) on p.patID equals h.patID into gj
            from h in gj.DefaultIfEmpty()
            select new { p.Surname, p.Othername, h.History };
  • 1
    Once you decided to answer, it would be nice if you also include some explanation. And of course make sure what you post at least compiles. Your does not, because it's missing the essential part for the issue - 'into gj` is not enough, it needs to be followed by `from h in gj.DefaultIfEmpty()` – Ivan Stoev Mar 24 '16 at 12:05
  • Thank you for response i edited my answer @IvanStoev – Alper Tunga Arslan Mar 24 '16 at 13:10