CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

NameValueList - Is this the correct implementation?

rated by 0 users
Not Answered This post has 0 verified answers | 0 Replies | 0 Followers

Top 50 Contributor
163 Posts
gajit posted on Thu, Feb 23 2012 1:54 PM

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
#If Not SILVERLIGHT Then
    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)
        Else
            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?

Thanks,

Graham

Page 1 of 1 (1 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems