Query with left join in linq
你好,我是想给在LINQ查询但我need some help…P></
我有两个表:langavailable and official translations我想,如果是在网上甚至还有不翻译记忆P></
例如:forP></
1 2 3 4 | LangId: 1 TranslationID:10 Translation: Hello LangId: 2 TranslationID:10 Translation: Bonjour LangId: 1 TranslationID:11 Translation: Thanks LangId: 2 TranslationID:11 Translation: |
这是我给你:P></
1 2 3 4 | Dim query = From c In db.LangAvailable _ Join o In db.Translate On c.ID_Lang Equals o.Lang_ID _ Where o.TranslationID = 243 _ Select New With {c.LangId, o.Translation} |
只给我一本记录if there in the translation table翻译的不…任何想法如何,我可以得到吗?P></
thanxP></
你可以使用GroupJoin来完成你想做的事情。试试这个:
1 2 3 4 5 | Dim query = From c In db.LangAvailable _ Group Join o In db.Translate On c.ID_Lang Equals o.Lang_ID Into Group _ From o In Group.DefaultIfEmpty() _ Where o.TranslationId = 243 _ Select LangId = c.ID_Lang, Translation = If(o.Translation Is Nothing, Nothing, o.Translation) |