1

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

1 Answer 1

4

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()
2
  • "Unable to cast object of type 'WhereListIterator1[RTS.BusinessEntities.Tap100transCodeInfo]' to type 'System.Collections.Generic.IList1[RTS.BusinessEntities.Tap100transCodeInfo]'." Apr 13, 2011 at 15:52
  • @user706311 added an addendum.
    – diceguyd30
    Apr 13, 2011 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.