您好我正在尝试在linq中进行查询,但我想我需要一些帮助......
我有两张桌子:langAvailable和Translations 即使没有翻译记录,我也想要一条“线”
例如:
LangId: 1 TranslationID:10 Translation: Hello
LangId: 2 TranslationID:10 Translation: Bonjour
LangId: 1 TranslationID:11 Translation: Thanks
LangId: 2 TranslationID:11 Translation:
这就是我的所作所为:
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}
如果翻译表中没有翻译,这只给我一条记录...... 知道我怎么能得到它吗?
感谢名单
答案 0 :(得分:2)
您可以使用群组加入来执行您尝试执行的操作。试试这个:
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)