Home All Groups Group Topic Archive Search About

Hooking ObjectDataSource Up to a Shared Generic Method

Author
20 Apr 2007 8:17 PM
Aeden Jameson
Hi Folks,

   I'm working with the ObjectDataSource class and I'm stuck on how I
can specify a shared generic method of my DAO in the SelectMethod
property of an ObjectDataSource.  For example,  I have

Public Class Repository

  Public Shared Function GetByID(Of T)(ByVal ID As Object) As T

End Class


I'd like to be to call something like Respository.GetByID(Of Order)
(Session("TheOrderID"))

Cheers,
Aeden

Author
20 Apr 2007 9:05 PM
Mattias Sjögren
Aeden,

>   I'm working with the ObjectDataSource class and I'm stuck on how I
>can specify a shared generic method of my DAO in the SelectMethod
>property of an ObjectDataSource.  For example,  I have
>
>Public Class Repository
>
>  Public Shared Function GetByID(Of T)(ByVal ID As Object) As T
>
>End Class
>
>
>I'd like to be to call something like Respository.GetByID(Of Order)
>(Session("TheOrderID"))

ObjectDataSource doesn't support generic methods, but seems to work
with generic types.

If you change your type to

Public Class Repository(Of T)
  Public Shared Function GetByID(ByVal ID As Object) As T
End Class

you should be able to use it by specifying
TypeName="Repository`1[Order]".


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

AddThis Social Bookmark Button