Geeks With Blogs
I [heart] code! .NET musings from the chick side

On my latest project, I needed to come up with a Business and Data layer(s) with the following requirements:

1) They wanted to use a code generation tool to automatically generate the classes whenever the database (which was still under development) changed

2) The business objects would basically mirror the database tables

3) I had a couple of days to deliver.

Michael Eaton suggested using Castle Active Record (which uses NHibernate). I found some Active Record templates for CodeSmith, and within a few days was up and running with a fully functional Business/Data layer. I created partial classes which allows me to regenerate the private and public properties and mappings as requested when the database changes, the business logic resides in partial classes that are untouched when the code regenerates.

While the Active Record pattern probably not be a good fit for any complex application or workflow, for a simple data in/data out application with a tight timeline that allowed no object modeling or middle tier design phase, it turned out to be a perfect fit.

A side benefit was going from 0 to 60 with NHibernate in a very short time. I am one of those people who can read a thousand pages in minutes (ok, not really, but close) but I don't really understand anything until I see it. Active Record sits on top on NHibby and you can watch it run while slowly making your use cases more and more complex. The CodeSmith templates and code generation allowed me to get classes up and running in 5 minutes and then learn how the mapping works by watching it run in my own application that I already understood.

Posted on Sunday, March 1, 2009 9:52 PM | Back to top


Comments on this post: Active Record to the rescue

# re: Active Record to the rescue
Requesting Gravatar...
NHibby... :0) I'm using that!

Great post.
~Lee
Left by Lee Brandt on Mar 02, 2009 2:32 AM

# re: Active Record to the rescue
Requesting Gravatar...
Actually ActiveRecord can be used on more complex apps than the most basic forms over data just because of nice things like ActiveRecordMediator

http://www.lostechies.com/blogs/johnteague/archive/2008/05/27/why-use-activerecordmediator-instead-of-nhibernate.aspx

using ActiveRecordMediator with a Repository pattern one can easily access most of the underlying power of Nhibernate but get up and running quickly, and not have to worry about session management unless they want to (you can still access the underlying ISession of nhibernate).

Fluent NHibernate and the like are awesome, but for most projects Castle ActiveRecord with the above approach work quite well for more complex scenarios.
Left by Ryan Svihla on Mar 02, 2009 5:38 PM

Your comment:
 (will show your gravatar)


Copyright © Kirstin Juhl | Powered by: GeeksWithBlogs.net