CodeSmith – Improved Sproc Generation Templates

Date Published: 27 January 2005

CodeSmith – Improved Sproc Generation Templates

I edited my first CodeSmith templates today and found it to be quite straightforward, and a very powerful tool. I think I’m going to be hooked. Anyway, I was using it to generate some CRUD sprocs for a couple of tables I need in a small project I’m working on now for, and I decided that the default templates that shipped with it didn’t fit my needs because my tables have prefixes on them and I didn’t want the prefixes to be in the sproc names (e.g. for a table sas_Product it was creating a sproc called Deletesas_Product instead of just DeleteProduct). So I fixed them and now you can specify a table prefix which is ignored when the sprocs are named (you can also set a global sproc prefix). In this way, all of my tables and sprocs have the same common prefix for each common piece of functionality, but the sprocs don’t have extra table prefixes in their names (end result is something like sas_DeleteProduct). You can download the updated templates here.

Steve Smith

About Ardalis

Software Architect

Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.