ANTS is saying that the Select
with the string.Compare
call is hit 90 million times because for each item in the main list, it is searching the entire list again.
Each of the primary 9000 iterations causes 9000 additional iterations, so the string.Compare
has to be called at least 81,000,000 times.
I would suggest building a cache of the grouping, and then use that to construct the LabItem
.
Maybe something like this:
var groupedItems = items.GroupBy(c => c.IDCode);
return items.Select(c =>
new LabItem(c.IDCode, c.OrderGuid, c.Name, c.SignificantDtm, c.Status, c.Description,
groupedItems.Where(d => string.Compare(d.Key, c.IDCode, true) == 0 ).SelectMany(group => group)));