I am missing something very basic, I don't know what... I get an exception on following Linq:
Dim arch As List(Of String)
'gets archive as String() and casts it as List
arch = client.GetArchive().ToList()
'here exception occurs: Cannot cast object of type 'WhereSelectListIterator`2'...
arch = From a In arch
Where a.EndsWith(System.Environment.UserName & ".htm")
Select a
The LINQ query syntax begins with from keyword and ends with the Select or GroupBy keyword. After from keyword you can use different types of Standard Query Operations like filtering, grouping, etc. according to your need. In LINQ, 50 different types of Standard Query Operators are available. Step 1: First add System.Linq namespace in your code.
For details about query clauses, see Visual Basic LINQ Query Operators later in this topic. For example, the following query identifies a source collection of customer data as the customers variable, and an iteration variable named cust.
Building LINQ Queries at Runtime in C# - Tomas Petricek Common criticism of LINQ is that it doesn't support a scenario where queries are build dynamically at the runtime.
In C# as in most programming languages a variable must be declared before it can be used. In a LINQ query, the from clause comes first in order to introduce the data source (customers) and the range variable (cust).
as it states, you're trying to store a where iterator to a list.
Try this:
arch = arch.where(Function(x)x.EndsWith(System.Environment.UserName & ".htm")).ToList()
I prefer extension linq, but it's just preference, and the reason mine will work is because of the ToList()
:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With