2

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

5

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()
Sign up to request clarification or add additional context in comments.

2 Comments

"Unable to cast object of type 'WhereListIterator1[RTS.BusinessEntities.Tap100transCodeInfo]' to type 'System.Collections.Generic.IList1[RTS.BusinessEntities.Tap100transCodeInfo]'."
@user706311 added an addendum.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.