RyanOC
RyanOC

Reputation: 97

Left outer Join with LINQ

Can someone help me translate this query to LINQ? I cant find a good way to translate it, Thanks!

SELECT
  C.id,
  C.id_old,
  C.cus_id,
  C.namefirst,
  C.title,

  CP.id as 'cus_phone_jct.id',
  CP.contact_id,
  CP.phone_id,
  CP.ext,

  P.id as 'cus_phone.id',
  P.phone,
  P.typ_id,
  P.status_id,
  P.donotcontact

FROM cus_contact C
LEFT OUTER JOIN cus_phone_jct CP ON C.id = CP.contact_id  
LEFT OUTER JOIN cus_phone P ON CP.phone_id = P.id
WHERE C.cus_id = 4

Upvotes: 4

Views: 903

Answers (1)

David Glenn
David Glenn

Reputation: 24522

Try,

from c in DataContext.cus_contact
join cp in DataContext.cus_phone_jct on c.id equals cp.contact_id into cp2 
  from cp3 in cp2.DefaultIfEmpty()
join p in DataContext.cus_phone on cp3.phone_id equals p.id into p2 
  from p3 in p2.DefaultIfEmpty()
where c.cus_id = 4
select 
  c.id,
  cp3.id
  ...

Upvotes: 6

Related Questions