CodeSmith Templates
One thing the VS.NET templates cannot do is connect to your database and generate code according to your real tables information. So all code in the VS.NET templates are given as an example of how things should be done.
To speed up the task of writting the 'real' code against a 'real' database CodeSmith can save a lot of time. The templates I provide are a derivative of some great templates from Scott McCulloch. Most of my work is based on his initial template. I just added some features and reordered things to adjust to my framework.
How to use CodeSmith.
After you have a module created with the templates you need the real code to connect to you database and tables. So, nearly all code in BLL, DataProvider.vb and SqlDataProvider and AccessDataProvider can be discarded, we'll generate it from CodeSmith. All you need to do is create the tables.
CodeSmith v3.0 templates are for DotNetNuke v3.
CodeSmith v1.2 templates are for DotNetNuke v2.
Start CodeSmith Explorer, navigate to the folder where you have the templates and run them:
- StoredProcedures.cst will generate all code to get, insert, update... data from your database. To run it manually against the DB you'll have to replace {databaseOwner} and {objectQualifier} with proper values.
- SqlDataProvider.cst will generate the code to add to your SqlDataProvider to connect to the previously generated stored procedures.
- DataProvider.cst. This is the module data abstract layer (which goes to DataProvider.vb)
- BusinessObject.cst. This template will generate the BLL for each table your module uses. The code should go to <tablename>BLL.vb. (Version 1.2)
- BLL Controller Class.cst and BLL Info Class.cst. These two templates will generate the two classes that were previously in BusinessObject.cst. They are now separated to follow DotNetNuke v3 standards.
Note: I use to create database objects using a diferent naming convention than the one used by DNN. I name my objects with a module prefix, a table prefix and a operation name suffix. I prefer this solution so all stored procedures related to any given module and table are displayed grouped in SqlServer Manager (or any other tool). So for a module [Test] which includes a table [Testing] I'll have these stored procedures (for example):
- Test_TestingGet
- Test_TestingInsert
- Test_TestingDelete
- ...
But, in VB.NET code I reverse the convention so when an object of a given type is created, when you type "." to get the object members, the operation is in front. Note that here tablename is not present. When we instantiate a new object controller we know which table are we working on, so repeating tablename for each method is a bit redundant and unnecessary. So for a TestingController object I'll have (for example):
More information on CodeSmith can be found here.
NOTE: These templates were created for CodeSmith version 2.5 / 2.6. If you download latest version (3.0) you will get some errors. Either you can use the previous version or follow the steps outlined in this thread to modify the templates so they can be run on CodeSmith 3.0 |