1

您好我正在尝试在 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}

如果翻译表中没有翻译,这只会给我一条记录......知道我怎么能得到那个吗?

谢谢

4

1 回答 1

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)
于 2012-11-21T18:21:11.097 回答