LINQ for 2 Tables

Hi! I am no good at LINQ and find it efficient vs multiple-for-each activity, especially on tables with thousands of rows. Hoping you could help me with the following scenario.

DataTable Reference has the following columns: Keyword, Domain, Type
DataTable FileToFilter has the following columns: Mailbody, Sender, Time Stamp, Type, Code

Now, if the string from Column: Mailbody(in dtFileToFilter) contains the string from Column: Keyword(in dtReference) AND if the string from Column: Sender( in FileToFilter) contains string from Column: Domain (in reference) Then the row value from DT Ref columns: Keyword and Type are copied respectively to DT FileToFilter Columns: Code and Type

Not sure if I am asking it correctly but below is the expected output

get supported for your learning by

@tep_b

Please try this

DtResult = (From t1 In dt1.AsEnumerable Join t2 In dt2.AsEnumerable On t1("MailBody").ToString Contains t2("Keyword").ToString And t1("Sender").ToString Equals t2("Key").ToString Let ra = New Object { t1("MailBody") .ToString, t1("Sender").ToString, t1("Timestamp").ToString, t2("Type").ToString,t2("Code").ToString)} select r= dtNew.Rows.Add(ra)).CopyToDataTable

Use a build datatable and build the dtNew with 5 columns as required…change dt1 and dt2 and column names as per your requirement

Hope this helps

Cheers

Cheers

I will surely check this out and improve my understanding, thank you good sir!