I have a data table in my ASP.NET web service project, this data table contains about 500 thousand records in it with 39 columns and is present in the cache. After a minute, the background thread enters the database and displays update records from the database that I want to update in the Cached data table, I use the following approach, but there is enough time for this:
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 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 takes about 5 minutes on my laptop.
Can someone point me where and what am I doing wrong? With which approach I can do this efficiently, I'm not sure if Dataset.Merge or any other approach can be used.
source share