C# GroupBy,然后根据C中的组排序另一个列表#

C# GroupBy,然后根据C中的组排序另一个列表#,c#,linq,sql-order-by,C#,Linq,Sql Order By,我有一个列表的对象,看起来像这样 class Item { int ItemId; string Name; DateTime CreatedDate; ... more properties, but not relevant ... } 还有一个有投票权的 class Vote { int ItemId; ... more properties, but not relevant ... } 因此,投票指向一个项目。我从数据库中收集了所有的

我有一个
列表
的对象,看起来像这样

class Item
{
    int ItemId;
    string Name;
    DateTime CreatedDate;
    ... more properties, but not relevant ...
}
还有一个有投票权的

class Vote
{
    int ItemId;
    ... more properties, but not relevant ...
}
因此,投票指向一个项目。我从数据库中收集了所有的选票,并将它们存储在一个列表中

var votes = GetAllVotes().ToLookup(v => v.ItemId).OrderByDescending(v => v.Count());
现在我有了一个列表,它给出了一个好列表中投票最多的itemId。是否有一种方法可以让我根据投票列表对项目列表进行排序

var items = GetAllItems().OrderBy(i => i.CreatedDate);
//then I want to do something like this:
items.OrderBy(votes.Select(v => v.Key, v.Count())

因此,这里的目标是按投票数对项目进行排序,所有投票数为0的项目都按日期进行排序。

听起来您想要的是:

from item in GetAllItems()
join vote in GetAllVotes() on item.ItemId equals vote.VoteId into votes
orderby votes.Count() descending, item.CreatedDate
select new { Item = item, Votes = votes.Count() };

(如果您愿意,我可以用非查询表达式表示法来表示,但不会那么简洁。)

是的。这正是我想要的,但我想你已经知道了,不是吗?你可能在我问这个问题前几分钟就把答案写在笔记本上了。