Attached you will find a zip file. This is the Teired solutions that I use.
We have several large client of ours using this model and it works great.
There are 4 files using Inhertiance which makes it simpler (for me at least)
to keep maintained.
Base.vb - is a must inherit class that basically contains all the fields in
the database and the types. With a function that set a default value in the
fields.
DataAccess.vb - is a must inherit class which inherits the Base class (to
get all the properties) but it can have it own property usually readonly
and the results of joins. This class allow for the updating, deleting, and
create of a single record in the in the database. This also contain
multiple record results in the form of a strongly type collection to reduce
processing overhead and bytes transmitted. Strongly typed collection can
still be bound to anything accepting a .DataSource. Also contain several
function to manage the cache (creation and expiration) of results and items
from the database
BusinessLogic.vb - Inherits the DataAccess class and contains the Validate
function to validate the updates and creates going into the database.
Collection.vb - Custom Strong Type Collection used in the DataAccess to
return results. Contains two classes ...Item and ...ItemCollection
(generated by CodeSmart)
At first this looks like a lot of code to create each time however I have
taken this style of code and using a templated based generation tool called
CodeSmith I created a custom template so I can generate about 90% all the
code I need in about 15 seconds. But some the advantanages are:
- all the data is cache reducing data hits
- all cache expires at 100 seconds (you can change this)
- all cached in managed force updated data out of cache only if it meets
certain criteria.
- business logic is only written one time.
- Everything is strongly typed allowing you to referece (set/get) fields the
Instance.FieldName
- Strongly type collection are by my testing faster, more flexable, and
smaller than Dataset.
- And with CodeSmith it can be generate very very quickly.
I am sure this answer is over kill for your question, but maybe you will
find something else you like in there too.
BTW. Once you do all the VB files you can just create an Reference to the
dll and then...
If you it a data collection you can reference it directly
Gizmo.DataSource = [Root Name Space].Role.GetAllRole()
Gizmo.DataBind
Or by an instance for create, drop, update.
' For create
Dim oRole as New [Root Name Space].Role()
oRole.Description = ""
oRole.Inactive = False
oRole.Create 'Returns a new unique identifier value if you want it
'For Edit key represent the unique row identifier. BTW, remember validation
of the field is done in the class no need for it here.
Dim oRole as New [Root Name Space].Role(Key)
oRole.Description = "Updated Role Description"
oRole.Update 'Returns true or false on the successful completion of process
'For Delete key represent the unique row identifier
Dim oRole as New [Root Name Space].Role(Key)
oRole.Delete 'Returns true or false on the successful completion of process
'Throws an error if business logic encounters an error
Try
Dim oRole as New [Root Name Space].Role(Key)
oRole.Description = "Updated Role Description"
oRole.Update ' or can be .Create or .Delete
Catch e As Exception
'Handle you error here any way you want.
End Try
'To get data out, single record, say a form, key represent the unique row
identifier
Dim oRole as New [Root Name Space].Role(Key)
txtDescription.Text = oRole.Description
cbxInactive.Check = oRole.Inactive
Somewhat straight forward.
-Wayne