Modification in a LINQ query

Hi All,

I wrote below LINQ to merge values of 2 columns into 1 by a delimiter and add the updated value in the new column, but this query is taking a lot of time to execute.
Expected data volume can be 300K to 400K rows

(From d In Dt_Table.AsEnumerable()
Let a = d("Check 1").ToString.Trim+"-"+d("Check 2").ToString.Trim
Let ra = d.ItemArray.Append(a).ToArray()
Select Dt_ClonedDt.Rows.add(ra)
).CopyToDataTable()

Can anyone please suggest some better more efficient LINQ query for the same functionality.

Thanks in advance for the help

@ppr @Yoichi @kumar.varun2 Can you also suggest something

Hi @Dhruvi_Arumugam ,

I believe you are trying to update a Column present in the Datatable, the value to update would be the Concatenation of two other Column values present.

If that is the case, Check with the Data Column Expression updation method like below :

Dt_Table.Columns("ColumnNameToUpdate").Expression = "[Check 1]+'-'+[Check 2]"
1 Like

Hi @Dhruvi_Arumugam

You can add a try catch add a log message and in it just add dt.columns.add(“column3”,gettype(string),”column1+’abc’+column2”)

Try catch is to handle column already exists error. But it will add the two columns and with delimiter and you will have your new concatenated column

Cheers

we agree to @supermanPunch as also mentioned here:

Hi @supermanPunch

Thanks for your response.

Just a small update in the question, that I want to merge the values of the columns will this expression approach work in that case as well? also how to implement this I have a huge data set consisting of 200-400K rows.

Thanks

@Dhruvi_Arumugam ,

Could you maybe provide a more descriptive explanation of what needs to be done maybe with an example ?

From the Linq Query provided, it did seem as you are updating the concatenated column values in a new/different column.

If this is not the case, maybe we need to understand with more details.

Yes you are right, If suppose there are 3 columns col1,col2,col3 then I am concatenating values of col1 and col2 by a delimiter and updating the new value in col3

@Dhruvi_Arumugam ,

Have you Checked with this Expression, It should be done using an Assign Activity.
For more details on it’s implementation, Check the post mentioned by @ppr

Thanks its working!!

1 Like

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