LINQ 쿼리를 사용하는 함수를 수정하여 각 항목에 추가 부울을 추가하여 데이터 컬렉션을 반환해야한다는 요구 사항이 있으므로 간단히 반환 유형을 KeyValuePairs
의 목록 그러나 나는 해결할 수 없거나 불행히도 이해할 수있는 오류가 있습니다. 다음VB.NET의 LINQ 쿼리 문제
원래 버전 또는 함수이다
Private Function GetSelectedExtractors() As List(Of ExtractionMapping)
Return _extractionSelections _
.SelectMany(Function(x) x.ExtractionRoutineSelection) _
.Where(Function(x) x.Selected) _
.Select(Function(x) x.ExtractionMapping)
End Function
새 버전의 오차 이하이다
Overload resolution failed because no accessible 'Select' can be called with these arguments:
Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of ExtractionRoutineSelection, Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': Nested function does not have a signature that is compatible with delegate 'System.Func(Of ExtractionRoutineSelection, Integer, TResult)'.
Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of ExtractionRoutineSelection, Integer, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of ExtractionRoutineSelection, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': 'DeleteExistingInstances' is not a member of 'Domain.ProductionWizard.ExtractionRoutineSelection'.
Extension method 'Public Function Select(Of TResult)(selector As System.Func(Of ExtractionRoutineSelection, TResult)) As System.Collections.Generic.IEnumerable(Of TResult)' defined in 'System.Linq.Enumerable': Data type(s) of the type parameter(s) cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
:
Private Function GetSelectedExtractors() As List(Of KeyValuePair(Of ExtractionMapping, Boolean))
Return _extractionSelections _
.SelectMany(Function(x) x.ExtractionRoutineSelection) _
.Where(Function(x) x.Selected) _
.Select(Function(x) New KeyValuePair(Of ExtractionMapping, Boolean) _
(x.ExtractionMapping, x.DeleteExistingInstances))
End Function
I 수신 오류가 이쪽
C#에서 많은 LINQ 쿼리를 수행했지만 VB에서는 그다지 많지 않으므로 잘 이해할 수 있습니다. 전자 구문. 성공하지 못했지만 몇 가지 변형을 시도했지만 KeyValuePair
과 반대되는 익명 유형으로 변환 할 수 있지만이 구현에는 적합하지 않습니다.
모든 해결책이나 정보를 제공해 주시면 감사하겠습니다. x.DeleteExistingInstances
이 유효처럼
을 '질문을 작성할 때 x.DeleteExistingInstances' 오타했다! 그러나, 내가 실제로 잘못된 클래스에 문제의 속성을 추가했다 것으로 나타났습니다 고정에! 나는 바보 같이 느낀다! 반면에 왜이 경우에 튜플을 선택하겠습니까? 나는 Tuples를 사용하지만 보통 출력물에 두 개 이상의 객체가있을 때 사용합니다. 당신의 의견에 관심이 있습니다. – XN16
데이터 사이에 실제 * 키 - 값 * 관계가있는 것처럼 보이지 않으므로. 첫 번째와 두 번째 어느 것도 키가 아닌 두 개의 값. 물론 - 당신은 더 큰 그림을 가지고 있을지도 모릅니다. 아마도 키 - 값 * 일 것입니다. 나는 그 방법으로 만 그런 식으로 그것을 보지 못합니다. – MarcinJuraszek
설명을 주셔서 감사합니다. 저는'KeyValuePair'를 오랫동안 사용 해왔다 고 생각합니다.'Tuple'이 이런 많은 상황에 사용될 수 있다는 것을 잊어 버렸습니다! – XN16