NameValueList - Is this the correct implementation?

NameValueList - Is this the correct implementation?

Old forum URL:

gajit posted on Thursday, February 23, 2012

I want to implement the NameValueList class for an Encapsulated Invoke Dataread model.

Here is the code:

Imports Csla
<Serializable()> _
Public Class CodeTypeList
    Inherits NameValueListBase(Of Integer, String)

    Private Shared list As CodeTypeList

    Public Shared Sub InvalidateCache()
        list = Nothing
    End Sub
    Public Shared Function GetNameValueList() As CodeTypeList
        If list Is Nothing Then
            list = DataPortal.Fetch(Of CodeTypeList)()
        End If
        Return list
    End Function
#End If
    Public Shared Sub GetNameValueList(id As Integer, callback As EventHandler(Of DataPortalResult(Of CodeTypeList)))
        If list Is Nothing Then
            DataPortal.BeginFetch(Of CodeTypeList)(id, Sub(o, e)
                                                           list = e.[Object]
                                                           callback(o, e)
                                                       End Sub)
            callback(Nothing, New DataPortalResult(Of CodeTypeList)(list, Nothing, Nothing))
        End If
    End Sub

    Private Overloads Sub DataPortal_Fetch()

        IsReadOnly = False

        Dim rlce = RaiseListChangedEvents

        RaiseListChangedEvents = False

        Using dalManager = DataAccess.DalFactory.GetManager()

            Dim dal = dalManager.GetProvider(Of DataAccess.ICodeTypeListDal)()

            Using data = dal.Fetch()
                While data.Read()
                    Me.Add(New NameValuePair(data.GetString(data.GetOrdinal("CODEVALUE")), data.GetString(data.GetOrdinal("CODEVALUE2"))))
                End While
            End Using

        End Using
        RaiseListChangedEvents = rlce
        IsReadOnly = True

    End Sub

End Class


I have created the necessary Dal and IDals for this. Is this the correct method? In CSLA 2 this was a single-class act, but to maintain portability I guess I need to go down the Dal route. Correct?



Copyright (c) Marimer LLC