Here's a "basic" CSLA .NET 2.0 editable root class. It pretty much illustrates all the things you can do in a class under the upcoming version of the framework. In particular note the way validation rules are handled and all the transactional options in the DataPortal_XYZ methods (presumably you'd pick one for your app
).
A CustomerTypes class is also included at the bottom, illustrating how to implement a name-value list that works with data binding.
Imports CSLA
<Serializable()> _
Public Class Customer
Inherits BusinessBase(Of Customer)
#Region " Business Methods "
Private mID As Integer
Private mLastName As String = ""
Private mFirstName As String = ""
Private mLastActivity As SmartDate
Private mType As Integer
Private mCity As String = ""
Private Shared mCustomerTypes As CustomerTypes
Public Property City() As String
Get
If CanReadProperty() Then
Return mCity
Else
Throw New System.Security.SecurityException( _
"Property read not allowed")
End If
End Get
Set(ByVal value As String)
If CanWriteProperty() Then
If Not mCity.Equals(value) Then
mCity = value
PropertyHasChanged()
End If
Else
Throw New System.Security.SecurityException( _
"Property write not allowed")
End If
End Set
End Property
Public Shared ReadOnly Property CustomerTypes() As CustomerTypes
Get
If mCustomerTypes Is Nothing Then
mCustomerTypes = Library.CustomerTypes.GetCustomerTypes
End If
Return mCustomerTypes
End Get
End Property
Public ReadOnly Property ID() As Integer
Get
Return mID
End Get
End Property
Public Property LastName() As String
Get
If CanReadProperty() Then
Return mLastName
Else
Throw New System.Security.SecurityException( _
"Property read not allowed")
End If
End Get
Set(ByVal value As String)
If CanWriteProperty() Then
If mLastName <> value Then
mLastName = value.ToUpper
PropertyHasChanged()
End If
Else
Throw New System.Security.SecurityException( _
"Property write not allowed")
End If
End Set
End Property
Public Property FirstName() As String
Get
If CanReadProperty() Then
Return mFirstName
Else
Throw New System.Security.SecurityException( _
"Property read not allowed")
End If
End Get
Set(ByVal value As String)
If CanWriteProperty() Then
If mFirstName <> value Then
mFirstName = value
PropertyHasChanged()
End If
Else
Throw New System.Security.SecurityException( _
"Property write not allowed")
End If
End Set
End Property
Public Property LastActivity() As String
Get
If CanReadProperty() Then
Return mLastActivity.Text
Else
Throw New System.Security.SecurityException( _
"Property read not allowed")
End If
End Get
Set(ByVal value As String)
If CanWriteProperty() Then
If mLastActivity <> value Then
mLastActivity.Text = value
PropertyHasChanged()
End If
Else
Throw New System.Security.SecurityException( _
"Property write not allowed")
End If
End Set
End Property
Public Property CustomerType() As Integer
Get
If CanReadProperty() Then
Return mType
Else
Throw New System.Security.SecurityException( _
"Property read not allowed")
End If
End Get
Set(ByVal value As Integer)
If CanWriteProperty() Then
If mType <> value Then
mType = value
PropertyHasChanged()
End If
Else
Throw New System.Security.SecurityException( _
"Property write not allowed")
End If
End Set
End Property
Public ReadOnly Property CustomerTypeText() As String
Get
If CanReadProperty() Then
Return CustomerTypes.Value(mType)
Else
Throw New System.Security.SecurityException( _
"Property read not allowed")
End If
End Get
End Property
#End Region
#Region " Business Rules "
Protected Overrides Sub AddBusinessRules()
AddRule(AddressOf Validation.CommonRules.StringRequired, _
"FirstName")
AddRule(AddressOf Validation.CommonRules.StringRequired, _
"LastName")
End Sub
#End Region
#