Hello,
I am getting a anonymous type from Linq Query inside a function.
How can I return the obtained values and use them outside the
function?
Do I need to create a new class?
Here is my code:
Public Shared Function GetStats() As ??????????????????
Dim database As New CodeDataContext
Dim statistics = database.Tags.Select( _
Function(t) New With { _
Key .Total = database.Tags.Count(), _
Key .Linked = database.Tags.Where( _
Function(tag) _
tag.FilesTags.Any() OrElse _
tag.ArticlesTags.Any()).Count() _
}).FirstOrDefault()
Return statistics ???????????????????
End Function
Thanks,
Miguel
chrisrock2@gmail.com - 06 Mar 2008 15:20 GMT
> Hello,
>
[quoted text clipped - 24 lines]
> Thanks,
> Miguel
It's possible to do this but it's bad practice. See here:
http://geekswithblogs.net/hinshelm/archive/2008/01/07/returning-an-anonymous-typ
e.aspx
Cor Ligthert[MVP] - 07 Mar 2008 04:43 GMT
Chris,
>It's possible to do this but it's bad practice. See here:
>http://geekswithblogs.net/hinshelm/archive/2008/01/07/returning-an-anonymous-typ
e.aspx
I have the idea that the writter of this article does not know Option Infer
On in a kind of way that replaces Option Strict Off.
With the difference that now Strongly typed types are created.
I did not really investigate what he wrote, but the OFF did look strange to
me.
Cor
Andrew Backer - 06 Mar 2008 21:09 GMT
Have you looked at a tool like Refactor Pro, which give you a refactoring
for extracting the anonymous type as a named type? Otherwise you need to
do it by hand.
// Andrew
> Hello,
>
[quoted text clipped - 22 lines]
> Thanks,
> Miguel