我似乎无法排序,因为它只排序第一个数字
int storageCapacity;
IEnumerable<ProductStorageCapacity> items;
if (int.TryParse(filter["StorageCapacity"], out storageCapacity) && storageCapacity > 0)
items = await context.ProductStorageCapacities
.Where(ps => ps.StorageCapacity == storageCapacity)
.OrderByDescending(ps => ps.StorageCapacity).ToListAsync();
else items = await context.ProductStorageCapacities
.OrderBy(ps => ps.StorageCapacity).ToListAsync();
任何帮助?
答案 0 :(得分:1)
在某处,你的StorageCapacity
是一个字符串。
查看此代码(实例:http://rextester.com/NZALE31796):
var intList = new []{0,500,1000};
var strList = new []{ "0", "500", "1000"};
Console.WriteLine(String.Join(",",intList.OrderByDescending(x => x)));
Console.WriteLine(String.Join(",",strList.OrderByDescending(x => x)));
输出结果为:
1000,500,0
500,1000,0
第一个结果是你期望订购ints降序。第二个是从相同的字符串输入中获得的。