Hi, I need some advise on creating a general Business Logic Layer for
my applications.
The approach I use today is to create a class with the same name as
the table, create a property for each field in the table, write
constructors, to create a new row, and a constructor to open an
existing row, write update, delete functions, write a static get
method, to get a list of all the rows in the table..
I have created a Code generator to write the class based on the
database table.
Do anyone of you have any advises/links to resources which describes
how this layer should be designed?
Thanks..
To illustrate my model I can give an example:
Table: Customer
Field: CustomerID int
Field: GivenName Char(50)
Field: LastName Char(50)
Class:
Imports System
Imports System.Configuration
Imports MS.DataAccessLayer
Namespace MyCompany.BusinessLogicLayer
Public Class Customer
Private _customerid As System.Int32
Private _givenname As System.String
Private _lastname As System.String
Public Property CustomerID() As System.Int32
Get
Return _customerid
End Get
Set(Byval Value As System.Int32)
_customerid = Value
End Set
End Property
Public Property GivenName() As System.String
Get
Return _givenname
End Get
Set(Byval Value As System.String)
_givenname = Value
End Set
End Property
Public Property LastName() As System.String
Get
Return _lastname
End Get
Set(Byval Value As System.String)
_lastname = Value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal CustomerID As System.Int32)
Dim _ds as dataset =
sqlhelper.ExecuteDataset(ConfigurationSettings.App Settings("connectionstring"),
_
"Customer_Select_BY_CustomerID", _
CustomerID)
Dim _row as DataRow = _ds.tables(0).Rows(0)
_CustomerID = _row("CustomerID")
_GivenName = _row("GivenName")
_LastName = _row("LastName")
End Sub
Public Sub Update()
if _CustomerID = 0 then
CustomerID = sqlhelper.ExecuteScalar(ConfigurationSettings.AppS ettings("connectionstring"),
_
"Customer_Insert", _
_GivenName, _
_LastName)
else
sqlhelper.ExecuteNonQuery(ConfigurationSettings.Ap pSettings("connectionstring"),
_
"Customer_Update", _
_CustomerID, _
_GivenName, _
_LastName)
End if
End Sub
Public Sub Delete()
sqlhelper.ExecuteNonQuery(ConfigurationSettings.Ap pSettings("connectionstring"),
_
"Customer_Delete", _
_CustomerID)
End Sub
Public Shared Function Get_All_Of_Customer() as CustomerCollection
Dim _ds as dataset =
sqlhelper.ExecuteDataset(ConfigurationSettings.App Settings("connectionstring"),
_
"Customer_Select_All")
Dim _col as new CustomerCollection
For each _row as datarow in _ds.tables(0).Rows
Dim _Customer as new Customer(_row("CustomerID"))
_col.Add(_Customer)
Next _row
Return _col
End Function
End Class
Public Class CustomerCollection
Inherits ArrayList
End Class
End Namespace