Datareader projection onto custom class

Posts   
 
    
epitka
User
Posts: 19
Joined: 13-Feb-2007
# Posted on: 16-Mar-2007 18:52:41   

Hi, need example of how to project datareader onto custom class. Doc. has datareader ->entitycollection & dynamic list -> custom class. Anybody has a sample?

epitka
User
Posts: 19
Joined: 13-Feb-2007
# Posted on: 17-Mar-2007 01:38:10   

Figured it out.

here is the code

   Dim roleGroups As New List(Of RoleGroupInfo)

      Dim query As IRetrievalQuery = RetrievalProcedures.GetDcsGetRoleGroupsByUserIdCallAsQuery(portalId, userId)
      Dim projector As New DataProjectorToCustomClass(Of RoleGroupInfo)(roleGroups)

      Dim adapter As New DataAccessAdapter()
      Try
        Dim reader As IDataReader = adapter.FetchDataReader(query, CommandBehavior.CloseConnection)
        Try

          Dim valueProjectors As New List(Of IDataValueProjector)()

          ' project value on index 0 in resultset on row "RoleGroupID"
          valueProjectors.Add(New DataValueProjector("RoleGroupID", 0, GetType(Integer)))
          valueProjectors.Add(New DataValueProjector("PortalID", 1, GetType(Integer)))
          valueProjectors.Add(New DataValueProjector("RoleGroupName", 2, GetType(String)))
          valueProjectors.Add(New DataValueProjector("Description", 3, GetType(String)))

          adapter.FetchProjection(valueProjectors, projector, reader)
          reader.Close()
        Finally
          reader.Dispose()
        End Try
      Finally
        adapter.Dispose()
      End Try