March 18, 2007
@ 07:49 PM

One area most developers tend to spend a lot of time "re-inventing the wheel" in is Database Access Code. DAL (Data Access Layer) code tends to be rather painful to write and is a pain to maintain when the underlying database structure changes.

The code generators I am focusing on for this post are specifically geared towards minimizing this particular pain point. They all support multiple databases, typically MS SQL, MySQL, VistaDB and Oracle at a minimum.

Most of them also give you a choice of Frameworks, or templates, to choose from which dictate how the data access code is generated. Template driven generators offer the most flexibility, at the cost of complexity. You can use the predefined templates for most jobs but you have the ability to choose to edit or create new templates.

This way you have the maximum amount of control. There are 4 tools that I have personally used that generally fit this category. But in the interest of at least semi completeness here are a couple of lists I used as starting points when I was investigating this topic

Christopher Shain at TheServerSide.NET has this list. And Richard Hundhausen  has this list as well. Beware, at some point in the past CodeSmith was apparently freeware. That is no longer true. But a lot of web resources still list it as freeware. (If I am wrong and it is still freeware please let me know!)

The tools I have personally used or evaluated are:

At this writing, Codesmith and LLBLGen Pro are not freeware, while MyGeneration and NHibernate are. Update: NHibernate is not a code generator, it is an ORM utility. This blog post title is inaccurate since I am evaluating these tools as ORM utilities not as code generators. So I have updated the post title.

Of the 4, Codesmith and MyGeneration are my favorites. They are both template based code generators and both offer a large library of templates, both free and fee based, to select from.

NHibernate is a .NET port of the Java ORM tool called Hibernate, and is the least flexible of the tools I tried, not to mention unnecessarily (IMHO) complicated to use.

LLBLGen Pro is powerful, but I found it cumbersome and difficult to understand. And I resent paying money for things that are difficult to use, especially when they are supposed to simplify my life!

So, my choice is CodeSmith and MyGeneration, next post we will take an in depth look at each!

Cheers,

Robert Porter