It's a pretty bad idea to read the whole database into memory and search it there. Searching is what databases are optimized for. The best thing you can do is to move that whole code into the database somehow, for example by executing a MERGE statement for each item in NewCol
.
However, if you can't do that, the next best thing would be to make CurrentCol
a dictionary with MSISDN
as the key:
// Somewhere... Only once, not every time you want to add new items
// In fact, there shouldn't be any CurrentCol, only the dictionary.
var currentItems = CurrentCol.ToDictionary(x => x.MSISDN, x => x);
// ...
foreach(var newItem in NewCol)
{
PortedNumberCollection existingItem;
if(currentItems.TryGetValue(newItem.MSISDN, out existingItem)
{
existingItem.RouteAction = newItem.RouteAction;
existingItem.RoutingLabel = newItem.RoutingLabel;
}
else
{
currentItems.Add(newItem.MSISDN, newItem);
}
}