I have a data table in my ASP.NET web service project, this data table has around 500K records in it with 39 columns and is present in Cache. After a minute a background thread hits the database and brings update records from database, which I want to update in the Cached data table, I am using following approach but it is taking good enough time to do it:
foreach (DataRow dRNew in dtNew.Rows)
{
DataRow row = dtOriginal.Select("ID=" + dRNew["ID"]).First();
row["Column1"] = dRNew["Column1"];
row["Column2"] = dRNew["Column2"];
row["Column3"] = dRNew["Column3"];
}
I have replaced the following line:
DataRow row = dtOriginal.Select("ID=" + dRNew["ID"]).First();
with
DataRow row = dtOriginal.AsEnumerable().Where(r => ((Int64)r["ID"]).Equals(dRNew["ID"])).First();
but in vain, it is taking like around 5 minutes on my laptop.
Can anyone please guide my where and what am I doing wrong? With which approach can I do it efficiently, I am not sure if Dataset.Merge
or some other approach can be used.