Help with linq lambda groupJoin

Hi everyone,

I need to join two diferent datatables with one column in common. I need almost all columns from one, and all columns from another. Im trying with groupJoin Lambda, but i can get it. It trows an anonimous object, how can i get a datarow to add it to the output datatable?

query
dtUno.AsEnumerable.GroupJoin(dtDos.AsEnumerable, Function(lef) lef(“id”), function(rig) rig(“id”), function(lef, rig) new With {.id = lef, .key = rig } )

dt1
id fecha precio tamaño
1 2024 56$ xxl
2 2024 86$ xl
3 2024 76$ l

dt2
id provedor sku tienda
1 mkp 45632 izcalli
2 rko 48632 portobello
3 lok 75632 puebla

Output
id fecha precio tamaño provedor sku
1 2024 56$ xxl mkp 45632
2 2024 86$ xl rko 48632
3 2024 76$ l lok 75632

@Jose_G,

I haven’t tried it and it’s from LLM but give it a try. Use this in Invoke code. activity

Dim result As New DataTable()
result.Columns.Add("id", GetType(Integer))
result.Columns.Add("fecha", GetType(String))
result.Columns.Add("precio", GetType(String))
result.Columns.Add("tamaño", GetType(String))
result.Columns.Add("provedor", GetType(String))
result.Columns.Add("sku", GetType(String))

Dim query = From rowUno In dtUno.AsEnumerable()
            Join rowDos In dtDos.AsEnumerable()
            On rowUno.Field(Of Integer)("id") Equals rowDos.Field(Of Integer)("id")
            Select result.LoadDataRow(New Object() {
                rowUno.Field(Of Integer)("id"),
                rowUno.Field(Of String)("fecha"),
                rowUno.Field(Of String)("precio"),
                rowUno.Field(Of String)("tamaño"),
                rowDos.Field(Of String)("provedor"),
                rowDos.Field(Of String)("sku")
            }, False)

query.CopyToDataTable(result, LoadOption.OverwriteChanges)

1 Like

thanks for the reply, but this can also be done in linq querysh using an assign activity, but the real dts are way more larger, like 30 and 45 columns. So its kinda complicated to build that output datatable. So im searching a lambda linq solution.

switch to the Query Syntax

share with us

  • the column structure from left and right table
    and let us know:
  • the needed join column
  • the needed column from table (left) and table (right)

UPD1 - Preview on options
there are several techniques to construct the row Array without the need to mention each column individually

used on the Datarow.ItemArray:

Hello @Jose_G

If the example is a true representation of the datatables in context of the amount of columns, then you could perhaps use the built-in activities for Join data table and Remove data column for the columns you dont want.
Alternatively use Filter data table (after joining) with your desired output columns defined.

If the amount of columns is very large then this of course explains why you would look for another solution.

Regards
Soren