我需要以正确的顺序为我的项目返回一个通用列表,并且我收到 InvalidCastException 错误。这是代码:
Dim lDt As List(Of Comment) = RemapCommentsForE1(so.CommentList). _
OrderBy(Function(x) x.CreateDate.Value). _
ThenBy(Function(x) x.Sequence). _
ThenBy(Function(x) x.SubSequence)
注意:
- CreateDate 是一个
Nullable(Of DateTimeOffset)
- 序列是一个
Nullable(Of Int32)
- 子序列是一个
Nullable(Of Int32)
我得到的确切错误是:
无法转换类型为“System.Linq.OrderedEnumerable
2[DTDataUploader.Comment,System.Int32]' to type 'System.Collections.Generic.List
1 [DTDataUploader.Comment]”的对象。
我已经尝试转换为实际类型...
Dim lDt As List(Of Comment) = RemapCommentsForE1(so.CommentList). _
OrderBy(Function(x) x.CreateDate.Value). _
ThenBy(Function(x) Convert.ToInt32(x.Sequence)). _
ThenBy(Function(x) Convert.ToInt32(x.SubSequence))
...但我得到同样的错误。我在这里想念什么?