Worked like a charm! :)
But could you explain why we need the OrderByDescending(x => x.Date).Take(1)? I know what that does but isn't it redundant? Doesn't the following select the highest bid of each group?
Bid =
bids
.Where(
x =>
x.Amount
==
bids
.Select(xx => xx.Amount)
.Max())
EDIT: I've just tried it without the OrderByDescending(x => x.Date).Take(1) and it still works. I'll wait for your explanation before I make up my mind. Here's what I got in my BiddingService now:
public IList<Bid> HighestBidsOnly(IEnumerable<Bid> allBids)
{
var bds = allBids.GroupBy(
x => x.Item.Id,
(itemId, bids) =>
new
{
ItemId = itemId,
Bid =
bids
.Where(
x =>
x.Amount
==
bids
.Select(xx => xx.Amount)
.Max())
//.OrderByDescending(x => x.Date)
//.Take(1)
.SingleOrDefault()
}
);
return bds.Select(x=>x.Bid).ToList();
}