2009-08-20 214 views
4

有人可以幫我翻譯這個查詢到LINQ嗎?我找不到翻譯它的好方法,謝謝!左外加入LINQ

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 
+2

URM,您可以簡化一點 - 就好像從每個表中的一個字段? – Benjol 2009-08-20 13:31:04

+0

而且請稍微格式化一下。現在我覺得自己喜歡把叉子給我看。 j/k – 2009-08-20 13:35:07

+0

更好嗎? – David 2009-08-20 13:38:36

回答

6

嘗試,

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 
    ... 
+0

這是完美的!我需要學習更多這些東西。它現在對我來說很陌生,謝謝! – RyanOC 2009-08-20 14:11:18