【发布时间】:2016-08-18 18:30:59
【问题描述】:
我有一个numbers 和number-letter 和letter-number 的列表。我的列的类型是字符串。我的数据是这样的:
1
14
3
S-34
2
36-1/E
26
S-14
20
S-2
19
36-1
30
35
S-1
34
但我想这样排序:
1
2
3
14
20
25
30
35
36-1
36-1/E
S-1
S-2
S-14
S-34
但我的代码是这样对数据进行排序的:
1
14
19
2
20
25
3
30
35
36-1
36-1/E
S-1
S-14
S-2
S-34
我的代码是:
List<ViewTestPackageHistorySheet> lstTestPackageHistorySheets = _reportTestPackageHistorySheetRepository.ShowReport(Id).OrderBy(i => i.JointNumber).ToList();
我更改了下面的代码但失败了。
List<ViewTestPackageHistorySheet> lstTestPackageHistorySheets = _reportTestPackageHistorySheetRepository.ShowReport(Id).OrderBy(i => Convert.ToInt32(i.JointNumber)).ToList();
错误是:
LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression.
【问题讨论】:
-
投反对票请评论
-
自定义字母数字排序器,它检查两个元素是否为数字,然后比较值,否则进行字符串比较,瞧,你会得到所需的输出