Reputation: 5792
I have LINQ result, and I have List. I want to do Where() on the LINQ and to REMOVE all the matching strings from the List.
I get errors of: Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator
What can I do?
Upvotes: 1
Views: 2988
Reputation: 15621
You need to make a copy (with ToList, which is faster than ToArray) of the items you're removing:
var removeMe = list.Where(...).ToList();
Now removeMe wil be safe to iterate through, however, a better approach would be to use the List.RemoveAll method, because then you don't need any temporary data structures
Upvotes: 2
Reputation: 887451
You need to call AsEnumerable()
or ToList()
before your Where
call to force LINQ-to-SQL to download all results to the client and perform a local Where
.
(Since your Where
call cannot be performed on the server, you need to do it on the client)
Upvotes: 3