Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Unable to cast object of type 'WhereSelectListIterator` in LINQ

I have BackgroundWorkerCollection which is a list of a specific class. When i try to loop into the list and filter and select a single i'm getting the mentioned error.


Dim bw = From BackgroundWorkerLinq In BackgroundWorkerCollection Where BackgroundWorkerLinq.Id = sItemNo Select BackgroundWorkerLinq.Backgroundworker

Is it possible to convert the bw to Backgroundworker, the class created in the application has two properties Id(int) and Backgroundworker(Backgroundworker). So i have to convert back to the same to check if that is busy or not.

Where i'm wrong and how to achieve that?

like image 854
A Coder Avatar asked Mar 22 '23 13:03

A Coder

1 Answers

bw will be a sequence of BackgroundWorker items - so you can't cast from that sequence to a single item. There are a number of methods which will give you a single item, e.g.

  • First
  • FirstOrDefault
  • Single
  • SingleOrDefault
  • Last
  • LastOrDefault

You should work out whether you should use one of those, or actually iterate over all the results of the query.

like image 196
Jon Skeet Avatar answered Mar 25 '23 03:03

Jon Skeet