2013-08-12 3 views
0

두 개의 컬렉션이 있고 값을 얻기 위해 조인을해야하지만 오류가 발생했습니다. // 코드LINQ를 사용하여 컬렉션의 내부 조인

: 위의 코드에서

Dim ExclusiveComment As ExclusiveComments = Nothing 

ExclusiveComment = From ExclusiveCommentLinq In Me.ExclusiveCommentsCollection 
        Join ExistingCommentsLinq In Me.CombinedExclusiveCommentsCollection On  ExclusiveCommentLinq.CommentDescription Equals ExistingCommentsLinq(0) 
        Select ExclusiveCommentLinq 

,

ExclusiveCommentsCollection = 컬렉션 클래스 (ExclusiveComments) CombinedExclusiveCommentsCollection = 정규 문자열 모음 (단일 열)의

모두 수집은 일반적인가 열 "CommentDescription"을 가지고 ExclusiveCommentsCollection에서 값을 가져와야합니다.

내가 어디에서 전화를 할 수 있고 어떻게 이것을 할 수 있습니까?.

오류 :에

옵션 엄격한는 (ExclusiveComments에 ExclusiveComments의) 'System.collections.generic.ienumarable에서 암시 적 변환

답변

2

을 허용하지 않습니다 문제 A는 항상 조인 "목록"의 결과이다 그 목록에는 하나의 객체 만 포함됩니다. 이 경우 마지막에 "FirstOrDefault"로 쿼리를 한정하면 하나의 결과 만 사용한다는 것을 나타낼 수 있습니다.

Dim ExclusiveComment As ExclusiveComments = Nothing 
ExclusiveComment = (From ExclusiveCommentLinq In Me.ExclusiveCommentsCollection 
        Join ExistingCommentsLinq In Me.CombinedExclusiveCommentsCollection On  ExclusiveCommentLinq.CommentDescription Equals ExistingCommentsLinq(0) 
        Select ExclusiveCommentLinq).FirstOrDefault 
+0

이제 "인덱스가 범위 밖으로 벗어남"오류가 발생합니다. 문자열 컬렉션을 제공하는 방법? 쿼리에서 – iamCR

+0

"ExistingCommentsLinq (0)"이 문제라고 생각합니다. ExclusingCommentLinq.CommentDescription이 ExistingCommentsLinq의 첫 번째 항목과 같게하려고한다고 가정합니다. 이 경우 Linq 외부에서 정의 된 별도의 변수를 사용하십시오. –

+0

아니요, 전체 컬렉션에서 검색하여 결과를 반환하고 싶습니다. 내가 어떻게 할 수 있니? – iamCR

관련 문제