VB.Net Linq Datatable Exists

Posted by LarsH on Stack Overflow See other posts from Stack Overflow or by LarsH
Published on 2010-05-05T13:14:50Z Indexed on 2010/05/05 13:18 UTC
Read the original article Hit count: 287

Filed under:
|
|

I would like to use Linq instead of below function :

Friend Function IsCollectionInTable2(ByVal apps As DataTable, ByVal collectionId As String) As Boolean
    For Each row As DataRow In apps.Rows
        If row("CollectionId").ToString = collectionId Then Return True
    Next
    Return False
End Function

The best I can do is below:

Friend Function IsCollectionInTable(ByVal apps As DataTable, ByVal collectionId As String) As Boolean
    Return (From row In apps.AsEnumerable()
             Where (row.Field(Of String)("CollectionId") = collectionId)
             Select row.Field(Of String)("CollectionId")).Count > 0
End Function

I would like to use Exists or Any in above function. Performance could be an issue,

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about LINQ