Brian
Brian

Reputation: 31

Linq - Left Outer Join - DataTables

I am wondering if anyone can help me. I am new to LINQ and still trying to understand how it fits together.

I have the following DataTables in memory:

currentDataTable    
previousDataTable

I want the LinQ query to return any transactions that exist in currentDataTable that do not exist in previousDataTable.

A SQL example below:

SELECT Table1.*
FROM Table1 LEFT JOIN Table2 ON Table1.DealReference = Table2.DealReference
WHERE (((Table2.DealReference) Is Null));

Can someone please guide me, how to achieve the same in LinQ.

Thanks

BM

Upvotes: 3

Views: 2082

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460138

Dim result = From c In currentDataTable    
             Group Join p In previousDataTable
             On c.Field(Of String)("DealReference") Equals p.Field(Of String)("DealReference")
             Into DataGroup = Group
             From row In DataGroup.DefaultIfEmpty
             Where row Is Nothing AndAlso c.Field(of String)("Counterparty") <> "*"
             Select c

Upvotes: 2

Related Questions