Replacing the CBO: How to make A Custom Hydrator for your DotNetNuke® Module

Also see:

In Performance, Performance, Performance Charles Nurse blogged about the performance hit of using the CBO (Custom Business Object) hydrator. He suggested creating your own custom hydrator.

In the Survey module I converted code such as this:

Public Shared Function GetSurveys(ByVal ModuleId As Integer) As List(Of SurveyInfo)
Return CBO.FillCollection(Of SurveyInfo)(DataProvider.Instance().GetSurveys(ModuleId))
End Function

To:

Public Shared Function GetSurveys(ByVal ModuleId As Integer) As List(Of SurveyInfo)
Dim SurveyInfolist As List(Of SurveyInfo) = New List(Of SurveyInfo)

Using dr As IDataReader = DataProvider.Instance().GetSurveys(ModuleId)
    While dr.Read
        Dim SurveyInfo As SurveyInfo = New SurveyInfo
        SurveyInfo.SurveyId = Convert.ToInt32(dr(
"SurveyId"))
        SurveyInfo.Question = Convert.ToString(dr(
"Question"))
        SurveyInfo.OptionType = Convert.ToString(dr(
"OptionType"))
        SurveyInfo.ViewOrder = Convert.ToInt32(ConvertNullInteger(dr(
"ViewOrder")))
        SurveyInfo.CreatedByUser = Convert.ToInt32(dr(
"CreatedByUser"))
        SurveyInfo.CreatedDate = Convert.ToDateTime(dr(
"CreatedDate"))
        SurveyInfolist.Add(SurveyInfo)
    End While
End
Using

Return
SurveyInfolist
End Function

Public
Shared Function ConvertNullInteger(ByVal Field As Object) As Integer
    If
Field Is DBNull.Value Then
        Return
0
    Else
        Return
Convert.ToInt32(Field)
    End If
End
Function

[Back to: The ADefWebserver DotNetNuke HELP WebSite]


DotNetNuke® is a registered trademark of Perpetual Motion Interactive Systems Inc.