LINQ query is taking a lot of time to execute

Hi All,

I am trying to filter line items from one data table which are not present in the master data table using a linq query .
But while executing the query is taking a lot of time to execute and it freezes in that state .

Please find below the LINQ query for your reference:
" (From x In dtSelectDataTable.AsEnumerable() where Not (From a In dtSelectDataTable.AsEnumerable() Join b In dtExport.AsEnumerable() On a(“GUI”).ToString() Equals b(“User”).ToString() select a).Contains(x) select x).CopyToDataTable() "

Please help me in resolving the same.

Thanks and Regards
Sushree Suravi

Hi @sushreesuravi_Bhuyan

Have you tried using Datatable.Select or you can use merge datatable based on that you can do the manipulations

Thanks
Ashwin S

Hi Ashwin,

Thanks for your quick reply . Can you please guide me with the code , like is anything wrong in the code?

Regards
Sushree Suravi

Hi @sushreesuravi_Bhuyan,

Greetings…!

Dt1.AsEnumerable().Where(Function(row) NOT Dt2.AsEnumerable.Any(Function(x) x(“GUI”).ToString=row(“User”).ToString)).CopyToDatatable

Try this…!

Thanks!

Hi @sushreesuravi_Bhuyan,

How many rows you have in each datatable, the GUI containing any special characters.

@kadiravan_kalidoss ,

It is throwing error “The source contains no datarow”

Regards
Sushree Suravi

Hi @sarathi125,

The master datatable contains almost 50,000 rows.

Thanks and Regards
Sushree Suravi

Try something like this,

From a In dtSelectDataTable.AsEnumerable() Join b In dtExport.AsEnumerable() On a(“GUI”).ToString() Not Equals b(“User”).ToString() select a).Contains(x) select x).CopyToDataTable()

  1. Rename Column name of “User” to “GUI” in dtExport datatable.
  • dtExport.Columns(“User”).ColumnName = “GUI”
  1. Then Execute this linq,
  • dtSelectDataTable.AsEnumerable().Where(Function(row) NOT dtExport.AsEnumerable.Any(Function(x) x(“GUI”).ToString=row(“GUI”).ToString)).CopyToDatatable

Try this…!

1 Like