I am confused which data type to define for my variable which stores value returned by LINQ Statement.
Currently I am defining it as some data type but its generating error like: ""Unable to cast object of type 'WhereSelectListIterator2″”`
Sample Code:
Private BaseRateList = List (of BaseCat)
Private myBase As BaseCat = Nothing
'''In some other proc
myBase = From BaseRate In BaseRateList _
Where BaseRate.UIN = 4 _
Select BaseRate
Here i want myBase to hold the data which has UIN = 4
It sounds like you just want a single value. The options you probably want to consider are:
SingleSingleOrDefaultFirstFirstOrDefaulte.g.
… depending on how you want it to behave if there are 0 or multiple matching values.
Or using the overload of
Single(etc) which takes a predicate: