Cannot iterate of a collection of Anonymous Types created from a LINQ Query in VB.NET

Posted by Atari2600 on Stack Overflow See other posts from Stack Overflow or by Atari2600
Published on 2010-03-17T20:32:39Z Indexed on 2010/03/18 0:01 UTC
Read the original article Hit count: 907

Filed under:
|
|
|

Ok everyone, I must be missing something here.

Every LINQ example I have seen for VB.NET anonymous types claims I can do something like this:

                    Dim Info As EnumerableRowCollection = pDataSet.Tables(0).AsEnumerable
                    Dim Infos = From a In Info _
                        Select New With {.Prop1 = a("Prop1"), .Prop2 = a("Prop2"), .Prop3 = a("Prop3") }

Now when I go to iterate through the collection(see example below), I get an error that says "Name "x" is not declared.

For Each x in Infos
 ...
Next 

It's like VB.NET doesn't understand that Infos is a collection of anonymous types created by LINQ and wants me to declare "x" as some type. (Wouldn't this defeat the purpose of an anonymous type?) I have added the references to System.Data.Linq and System.Data.DataSetExtensions to my project. Here is what I am importing with the class:

Imports System.Linq
Imports System.Linq.Enumerable
Imports System.Linq.Queryable
Imports System.Data.Linq

Any ideas?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about anonymous-types