Linq to Entity Left outer join
1.此方法等同 SQL Left Outer Join 效果 EF V1(.FrameWork 3.5)所能使用的方法.
Dim qbase = From sp In ctx.SysPhrase _
Where (sp.Owner = DivCode Or sp.Owner = FormCode) _
And sp.PhraseType = PhraseType And sp.Enabled = True _
Let Value = (From sc In ctx.SysCodeDefinition _
Where sc.CodeName = "GroupType" And sc.CodeValue = sp.GroupType _
Select sc.CodeDescription, sc.CodeValue).FirstOrDefault _
Select New With {.PhraseName = sp.PhraseName, sp.GroupType, sp.PhraseContent,sp. ViewSeq,.CodeDescription = Value.CodeDescription}
dt = LINQGet.LINQToDataTable(qbase)
2.此方法等同 SQL Left Outer Join 效果 EF V4(.FrameWork 4.0)所能使用的方法,V4才支援DefaultIfEmpty.
Dim qbase = From sp In ctx.SysPhrase _
Group Join c In ctx.SysCodeDefinition On sp.GroupType Equals c.CodeValue _
Into Code = Group _
From cp In Code.DefaultIfEmpty _
Where (sp.Owner = DivCode Or sp.Owner = FormCode) And sp.PhraseType = PhraseType And sp.Enabled = True And cp.CodeName = "GroupType" _
Select New With {.PhraseName = sp.PhraseName, sp.GroupType, sp.PhraseContent, sp.ViewSeq, .CodeDescription = cp.CodeDescription}
dt = LINQGet.LINQToDataTable(qbase)