0

我有两个集合,我必须进行连接才能获得一个值,但是当我尝试它时会抛出错误。

//代码:

 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

你能告诉我我错在哪里以及如何做到这一点吗?

错误:

选项严格禁止从 'System.collections.generic.ienumarable(Of ExclusiveComments 到 ExclusiveComments) 的隐式转换

4

1 回答 1

2

问题是连接总是会产生一个对象的“列表”,即使该列表只包含一个对象。在这种情况下,您只需要在末尾使用“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
于 2013-08-12T12:59:44.763 回答