Data Tier Generator

In our last episode, I was trying to come up with a CodeSmith template that could generate my Data Tiers. CodeSmith does come with a huge bundle of pre-written templates. But, I wanted to go ahead and write my own firstly because I wanted to explore CodeSmith’s capabilities. Secondly, I have my own style of writing entity classes and needless to say, the existing templates didn’t fit my mould.

Before I get started, there’s one thing I should note: If you’re reading a template written by someone else, trust me, you will find it extremely difficult to follow. Other than for the obvious reasons, this is partly due to the fact that its extremely difficult to get the formatting just right on both the generated code as well as the template code. The template writer would of course try to get the generated code as readable as possible, and break the formatting of the template while doing so. Getting back to the task at hand, you should know that I’m one of those people who just hate working with databases. To me, something about them feel very low tech. So this is in part, an attempt to escape the torture of creating tables, store procs and writing data plumbing code and the like.

Here are my end-goals:

  1. To come up with an easy to follow XML configuration format that would drive the code generation. The config file would be the only input an end user would need to code.
  2. Generate the SQL required for creating tables, indexes and relationships.
  3. Generate stored procedures that perform basic CRUD and retrieval operations
  4. Generate the C# entity classes along with the C# methods for data retrieval and manipulation.

The template I have so far created can be found here (11.65 kb). You may also want to check out the XML that would drive this template. I’ll get in to more details about each of these components in my future posts.

2 thoughts on “Data Tier Generator

  1. Well, to tell you the truth I started working on the templates the moment I got my hands on CodeSmith. I knew that there were plenty of built in helper classes in CodeSmith itself. But, since I knew .NET XML classes well enough, I didn't take the time out to read up on them. If I did, I'm sure I'd have saved a lot of lines of code.

    Thanks for taking a look at my templates. I enjoyed writing them. CodeSmith is indeed a great tool.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.