开发者

Determine the type of Object to use to store a Linq Query

开发者 https://www.devze.com 2023-01-05 20:09 出处:网络
I am using VB .Net for this, so I don\'t have acces开发者_Python百科s to var or this would be a simple matter.

I am using VB .Net for this, so I don't have acces开发者_Python百科s 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?


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]

0

精彩评论

暂无评论...
验证码 换一张
取 消