Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not run basic LINQ query

Tags:

vb.net

linq

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
like image 593
Michał Turczyn Avatar asked Oct 24 '17 08:10

Michał Turczyn


People also ask

How to use LINQ query syntax?

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.

What is an example of a Visual Basic LINQ query?

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.

Can LINQ queries be built dynamically at runtime?

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.

What comes first from or from in a LINQ query?

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).


1 Answers

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() :)

like image 120
Sasha Avatar answered Sep 26 '22 13:09

Sasha