Linq Group By 쿼리가 작동합니다. 나는 결과를 delare려고하고 InvalidCastException이을 타격하고, 그래서 익명 형식 작업을 좋아하지 않는다VB.Net Linq 그룹에 대한 InvalidCastException
Dim query = From fb As Feedback In lst Where fb.Seller.login_name.ToLower = UserName.ToLower
Order By fb.transaction_id Descending, fb.creation Descending _
Group fb By fb.transaction_id _
Into Group
다음은 쿼리입니다.
Debug.Print(query.GetType.ToString)
반환 :
System.Linq.GroupedEnumerable`4[Feedback,System.Nullable`1[System.Int32],Feedback,VB$AnonymousType_0`2[System.Nullable`1[System.Int32],System.Collections.Generic.IEnumerable`1[Feedback]]]
과 내부 유형 :
Debug.Print(item.GetType.ToString)
결과 :
VB$AnonymousType_0`2[System.Nullable`1[System.Int32],System.Collections.Generic.IEnumerable`1[Feedback]]
012,351,641 여기
는 유형 정보입니다
가
Unable to cast object of type 'System.Linq.GroupedEnumerable`4[Feedback,System.Nullable`1[System.Int32],Feedback,VB$AnonymousType_0`2[System.Nullable`1[System.Int32],System.Collections.Generic.IEnumerable`1[Feedback]]]' to type 'System.Collections.Generic.IEnumerable`1[System.Linq.IGrouping`2[System.Nullable`1[System.Int32],System.Collections.Generic.IEnumerable`1[Feedback]]]'.
추한 용액은 다음과 같은 목적을 정의하고 결과를 탐색한다 : 여기서
Dim query As IEnumerable(Of IGrouping(Of Int32?, IEnumerable(Of Feedback)))
에러가 반환 같습니다
그래서,이 정보로 무장 한, 여기에 사용 선언이다
0 :Class FeedbackDataItem
Sub New(ByVal transaction_id As Integer)
_transaction_id = transaction_id
_feedbacks = New Feedbacks(Of Feedback)
End Sub
Private _transaction_id As Integer
Public Property transaction_id() As Integer
Get
Return _transaction_id
End Get
Set(ByVal value As Integer)
_transaction_id = value
End Set
End Property
Private _feedbacks As Feedbacks(Of Feedback)
Public Property Feedbacks() As Feedbacks(Of Feedback)
Get
Return _feedbacks
End Get
Set(ByVal value As Feedbacks(Of Feedback))
_feedbacks = value
End Set
End Property
End Class
그리고 컬렉션을로드
이 오류가 발생하는 이유는 무엇입니까? 결과를 정의하고 데이터를 사람이 처리하는 대신 다시 테스트하는 것이 더 좋을 것입니다. 내가 놓친 게 있니?
정확히 그게 내가 도달했습니다 :) 내 대답을 지금 삭제 ... –
이것은 대단한 작품입니다 - 고마워요! – Graeme