プロジェクトのジェネリックリストを正しい順序で返す必要があり、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)
私が得ている正確なエラーは次のとおりです。
2[DTDataUploader.Comment,System.Int32]' to type 'System.Collections.Generic.List
タイプ'System.Linq.OrderedEnumerable1 [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))
...しかし、同じエラーが発生します。ここで何が欠けていますか?