LINQ query to replace column datatable in uipath

Feel free to open a seperate Topic on it or reach me by message.

The most important factor on an implementation is maintainability and that there is a chance to track the processing.

Using a Linq in an Assign statement is forcing that the LINQ Statement is returning something (L-Value assignment). Updating a column will fail:

  1. ) dt.AsEnumerable.Where(Function ( r ) r.Field(Of Int32)(0) < 2).Select( <- return is needed
  2. ) other tricks e.g. return someting and do col update will not validate
  3. ) dt.AsEnumerable.Where(Function ( r )r.Field(Of Int32)(0) < 2).toList.ForEach(Function (r) r.SetField( <- return is needed, SetField is a SUB(routine, no return)

Thats why the trick with adding new rows to empty datatable works as DataTable.Rows.Add… is returning the datarow (a later copyToDataTable we wouldn’t need, we just take it for getting something returned)

Shifting to e.g. Invoke Code would allow to do things without mandatory return needs. But then we put it like in a blackbox. This is against/stressing the principle from above.

Thats why updating within a for each, other well balanced LINQ/ForEach/essential Activities combination are prefered.

For sure with other priorities / principles technically it can be done different e.g. as described in 3. ). it is up to everyones personal decission.