Reputation: 41
I am using LINQ - VB.Net
I want to filter my List object by passing String object in the where.
Dim _permittedTransactionCodes As List(Of String) = Nothing 'String object
it is populated with data.
Dim tap100transCodeInfos As List(Of Tap100transCodeInfo) = _dal.GetActiveTap100transCodeByHdrScreenCde(UCase(screenId), "TRAN_CDE")
i am trying something below, but not getting the filtered results
tap100transCodeInfos.Where(Function(x) _permittedTransactionCodes.Contains(x.TranCde))
any idea?
Thanks
Upvotes: 1
Views: 8785
Reputation: 2752
Make sure to assign the output of the Where
function to a variable. Where
does not filter the existing list, but returns a new filtered list.
Dim result As IEnumerable(Of Tap100transCodeInfo) = _
tap100transCodeInfos.Where(Function(x) _
_permittedTransactionCodes.Contains(x.TranCde) _
)
Then result
should have the filtered results.
EDIT:
Where
returns an IEnumerable(Of T)
so if you are assigning the output to the same variable you need to append .ToList()
to the end of the statement (or define tap100transCodeInfos
to be an IEnumerable(Of Tap100transCodeInfo)
from the start).
tap100transCodeInfos = _
tap100transCodeInfos.Where(Function(x) _
_permittedTransactionCodes.Contains(x.TranCde) _
).ToList()
Upvotes: 4