Code Generation or O/R Mapping?

posted on 03/04/06 at 01:05:22 am by Joel Ross

I'm going to be doing a major revamp of the business and data layers of an application I have. Right now, it's mainly data readers and dataviews being used, with a few custom business objects. While it works, and is efficient for the task, I programming will be easier and less error prone if I can switch to a domain model with all business objects.

Which brings me to my question. Which is better? Code generation or O/R mapping? I'm a huge fan of CodeSmith, and recently got a license for version 3. I've generated thousands and thousands of lines of code with CodeSmtih, so I'm familiar with it. I've never done anything beyond a sample application with any O/R mapper, so I'm fairly new at it.

Here's where I see the advantages and disadvantages for each one. Let's start with code generation. You have complete flexibility. You can create your objects just the way you want them. You can inherit from your own base class, or not have one if you don't want one. The downside is that if you change your data model, you have to touch the objects to reflect those changes. Plus, while a tool like CodeSmtih is awesome, it can be cumbersome to create the initial template (hint: create a class the way you want it, and back into a template).

For O/R mappers, a lot require you use a base class that all objects have to inherit from. This limits your flexibility. Others have requirements on how you have to do things, which again limit your flexibility. The advantage is that there's basically no data layer?- it's generated (usually on the fly) by the O/R mapping software, and "just works."

Right now, I'm leaning toward generating everything, but I can stil be persuaded. What's the best O/R mapper you've used (and remember, I'm cheap!)? Would you rather generate or map?

Technorati Tags: | |

Categories: Development