I have one List of objects that looks somthing like this
class Item
{
int ItemId;
string Name;
DateTime CreatedDate;
... more properties, but not relevant ...
}
and another that holds votes
class Vote
{
int ItemId;
... more properties, but not relevant ...
}
So the vote points to an item. I’ve gathered all the votes from the database, and stored them in a List
var votes = GetAllVotes().ToLookup(v => v.ItemId).OrderByDescending(v => v.Count());
Now I have a list that gives me the itemId’s with the most votes in a good list. Is there a way for me to sort my list of items based on the votes list?
var items = GetAllItems().OrderBy(i => i.CreatedDate);
//then I want to do something like this:
items.OrderBy(votes.Select(v => v.Key, v.Count())
So the goal here is that the items gets sorted by number of votes, and all the items with 0 votes keep their sorting by date.
It sounds like you want something like:
(I can put that in non-query-expression notation if you want, but it won’t be as neat.)