Linq query ia creatting duplicates and how to avood creating duplicates in datatable h

Linq query is creating duplicates and how to avoid creating duplicates in datatable i am using linq query to compare id of two datatable dt1 and dt2 and selecting two columns from dt2

Hi
Youcan delete duplicates rows after unique rows with below linq query post comparimg id

Dt=dt.Asenumerable().groupby(Function(a) tuple create(a(Columm name).tostring).select(Function(b) b.first).copytodatatable()

Thanks,
Suresh

In UiPath, you can use LINQ to DataTables to compare two DataTables (dt1 and dt2) based on a specific ID column and avoid creating duplicates. The Distinct method in LINQ can help filter out duplicates. Here’s an example:

Dim queryResult = (From rowDt2 In dt2.AsEnumerable()
                   Join rowDt1 In dt1.AsEnumerable() On rowDt2.Field(Of Integer)("ID") Equals rowDt1.Field(Of Integer)("ID")
                   Select New With
                   {
                       .ID = rowDt2.Field(Of Integer)("ID"),
                       .Value = rowDt2.Field(Of String)("Value")
                   }).Distinct()

Dim resultDataTable As DataTable = queryResult.CopyToDataTable()

In this example, the LINQ query joins the two DataTables (dt1 and dt2) based on the “ID” column and selects the “ID” and “Value” columns from dt2. The Distinct method ensures that only distinct rows are selected.

Make sure to adjust the column names and types according to your actual DataTable structures.

If you’re still facing issues with duplicates, you may want to inspect your data to understand why duplicates are being generated. Also, ensure that the join condition and the columns selected are appropriate for your use case.

thanks
Linq queey
Its worked

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