views:

21

answers:

1

I am using VB .Net for this, so I don't have access to var or this would be a simple matter.

Right now my query is as follows

Dim errors As IOrderedQueryable(Of IGrouping(Of String, RSError)) = (From e In db.RSErrors 
                                                                     Where e.UserID = "msarchet" 
                                                                     Group e By e.Type Into t = Group).AsEnumerable

So I used this query in LinqPad to help me determine what the object would look like. I got back a IOrderQueryable(Of RSError) which then contained a IGrouping(Of String, RSError) for each grouped collection of objects returned by the query.

However I ended up with the current object type of errors as IOrderedQueryable(Of IGrouping(Of String, RSError)) because of the cast error I am getting in VS.

Unable to cast object of type 'System.Data.Linq.DataQuery1[VB$AnonymousType_12[System.String,System.Collections.Generic.IEnumerable1[RSSAdmin2.RSError]]]' to type 'System.Linq.IOrderedQueryable1[System.Linq.IGrouping2[System.String,RSSAdmin2.RSError]]'.

I'm not sure how to get rid of the VB$AnonymousType_1 Part of the returned object.

Am I even on the right track here or am I missing something completely?

+1  A: 

Can you try the following

Dim errors = (From e In db.RSErrors 
              Where e.UserID = "msarchet" 
              Group e By e.Type Into t = Group).AsEnumerable

Doing it this way basically sets it to

Dim errors As Object [Whatever the expression returns]

rockinthesixstring
I could do it Implicitly...sigh this is what I get for working under conditions that require Explicit declaration all the time.
msarchet
@rockinthesixstring, yes I understand what the implicit declaration does, and it works, thank you for jump starting my saturday brain
msarchet
No, it won't create the type `Object`. This changed in VB9 and it will actually create the specific type that the expression returns, just like the `var` keyword in C# 3.
Guffa
@Guffa, I think you're right. Thanks for the correction.
rockinthesixstring