I want to delete items only if the name exists more than once and the price is $ 500
Apple 300 <-- winner
Apple 500 <-- dupe
Banana 500 <-- winner
Banana 500 <-- dupe
Banana 500 <-- dupe
Cantelope 100 <-- winner
Cantelope 200 <-- winner
The second apple is a hoax, obviously. A banana has three items with a price == 500. One of them is the winner. The rest are deceptions. No price == 500 Cantelopes, so there is no cheating, just winners.
from item in source
group item by item.Name into g
let okItems = g.Where(x => x.Price != 500)
let secondChoiceItem = g.FirstOrDefault(x => x.Price == 500)
let theItems = okItems.DefaultIfEmpty(secondChoiceItem)
from nonDupeItem in theItems
select nonDupeItem
Amy b source
share