0

基本上,我有一个类似的声明

Contents
.Where(x=>x.CategoryId==5 && x.Status==1)
.GroupBy(q=>q.VersionId)
.OrderByDescending(q=>q.Key)
.Take(100)  
.Select(q => new { VersionId = q.Key, MajorVersion = q.Max(x => x.MajorVersion) })

目前,它看起来像下面。但我想将 MajorVersion 字段重新排序为降序...

VersionId     MajorVersion
387276        2
365015        1
355427        3
369865        1

我怎么做?

4

2 回答 2

2

Select returns an IEnumerable so you can do further sorting/ordering etc after.

Contents
.Where(x => x.CategoryId == 5 && x.Status == 1)
.GroupBy(q => q.VersionId)
.OrderByDescending(q => q.Key)
.Take(100)  
.Select(q => new { VersionId = q.Key, MajorVersion = q.Max(x => x.MajorVersion) })
.OrderByDescending(x => x.MajorVersion);
于 2013-03-05T16:30:10.850 回答
1

只需移动OrderByDescending. 然后,您将能够按选择中的字段进行排序。(因为您将调用由返回的匿名类型的 IQueryable )Select
OrderByDescendingSelect()

于 2013-03-05T16:27:37.623 回答