简体   繁体   中英

Linq to SQL translation to SQL syntax

I'm trying to do the following query in Linq

SELECT *
FROM Table1 T1
INNER JOIN Table2 T2
ON T1.ID = T2.AnotherID
LEFT OUTER JOIN Table3 T3
on T1.ID = T3.AnotherID

It works as expected in proper SQL syntax, but i'm having a hard time translating it to the corresponding Linq to SQL syntax.

How do i combine left join with an inner join?

Regards,

var results = from t1 in Table1
   from t2 in Table2
   where t1.ID = t2.AnotherID
   join t3 in Table3 on t1.ID equals t3.AnotherID into joined
   from j in joined.DefaultIfEmpty()
   select new {t1, t2, t3 = j}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM