I have an issue with LINQ in vb.net. Basically I want create LEFT JOIN between two datatables.
This is the info of the two datatables:
Dim vDT1 As Ne
The key is to call FirstOrDefault()
on the group. Then you either have the first row in the group or Nothing
.
Dim query =
From a In vDT1.AsEnumerable
Group Join b In vDT2.AsEnumerable
On a.Field(Of String)("Key") Equals b.Field(Of String)("Key")
Into Group
Let b = Group.FirstOrDefault
Select Key = a.Field(Of String)("Key"),
Data1 = a.Field(Of String)("Data1"),
Data2 = a.Field(Of String)("Data2"),
Data3 = If(b Is Nothing, Nothing, b.Field(Of String)("Data3")),
Data4 = If(b Is Nothing, Nothing, b.Field(Of String)("Data4"))
' Or Simply
'Select a, b