Reputation:
Hello I 'm trying to do a query in linq but I think I need some help...
I have two table: langAvailable and Translations I want a 'line' even if theres no translation recorded
For instance:
LangId: 1 TranslationID:10 Translation: Hello
LangId: 2 TranslationID:10 Translation: Bonjour
LangId: 1 TranslationID:11 Translation: Thanks
LangId: 2 TranslationID:11 Translation:
Here's what I do:
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}
This only give me one record if there s no translation in the translate table... Any idea how I can get that?
Thanx
Upvotes: 1
Views: 5683
Reputation: 4386
You can use Group Join to do what you're trying to do. Try this:
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)
Upvotes: 1