How to left join two tables using Linq Query with all data in left table? Please Help

How to left join two tables using Linq Query with all data in left table? Please Help

I need to left join two datatables “DT1” & “DT2” on Column “ID” and the result to be stored in FinalDT.

Query Used:
(From a In DT1
Join b In DT2
On a(“ID”).ToString Equals b(“ID”).ToString
Select FinalDT.LoadDataRow (New Object() {
a.Field(Of String)(“ID”), a.Field(Of String)(“Name”), a.Field(Of String)(“Designation”)
b.Field(Of String)(“Grade”)
},False)).CopyToDataTable()

I need to solve this in LinQ Query instead of using Join Data table activity:

Please help me

@GuhanTM
In general this could be done with Group Join

(From d1 In dtData1.AsEnumerable
Group Join d2 In dtData2.AsEnumerable On d1(0) Equals d2(0) Into gj = Group
From g In gj.DefaultIfEmpty
Select ra = {d1(0), d1(1) ,If(isNothing(g), Nothing, g(1)) }
Select dtResult.Rows.Add(ra)).CopyToDataTable

find starter Help here:
LINQ_LeftOuterJoin.xaml (9.7 KB)

11 Likes

Thank you very much @ppr
Its working good and the result is exactly as expected.
Thanks again

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.