Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 956
Brian Avatar asked Aug 24 '26 06:08

Brian


1 Answers

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
like image 190
Tim Schmelter Avatar answered Aug 27 '26 00:08

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!