Unable to pass object of type WhereSelectListIterator to LINQ

I have a BackgroundWorkerCollection, which is a list of a specific class. When I try to loop over the list and filter and select one, I get the error indicated.

//The code

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

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

Where am I mistaken and how to achieve this?

+4
source share
1 answer

bw will be a sequence of BackgroundWorker elements - so you cannot drop this sequence into one element. There are several methods that will give you one element, for example

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

You must decide whether to use one of them or actually iterate over all the query results.

+7
source

Source: https://habr.com/ru/post/1500710/


All Articles