Justin Blog

O/R mapper fanboy

oh sweet nectar of the gods… why have I not used an O/R mapper until now?!

I've been building data driven websites for a few years now, but up until recently it was mostly by hand. I had deluded myself into thinking it would make me a better programmer if I didn't rely on code generation, instead it just singed into my brain the same old uninteresting crap project after project. I never really had time to try some of the more abstract ideas in either database design or OOP since I was always rewriting the same damn db access routines.

Well with two deadlines fast approaching I took a look at Codesmith, Damian swears by it, so I figured I'd give it a shot. I put some time in and got it generating my sprocs and C# base classess for each table with the respective sproc calls. It wasn't too bad, my productivity did improve but table joins turned out to be an immense pain in the ass. I could either do it via ADO.NET and thus punish SQL Server with a bunch of iterative calls or I could go back and start writing custom sprocs and defeat the purpose of using Codesmith to begin with.

I would catch the occasional weblogs.asp.net post on O/R mappers from Frans Bouma or Paul Wilson but never anything beyond that. With my deadlines weighing down on me I decided to give Frans Bouma's LLBLGen Pro a whirl. Within a few hours I was making use of the DAL it generated. I've been picking up the intracies of the generated code over the last five days and all I can say is.... DAMN! Talk about a productivity increase. This thing is awesome.

And just to keep SQL Server in the mix (this is a SQL Server oriented site after all), an O/R mapper will force you to get rid of some of your bad DB design habits. I used to have a habit of enforcing RI through stored procedures. No more, if you don't declare your pk/fk relationships then you will be robbed of most of an O/R mapper's functionality. Normalized databases with referential integrity = O/R mapper goodness.

Legacy Comments


Jay
2004-11-25
re: oh sweet nectar of the gods... why have I not used an O/R mapper until now?!
Yes indeed! O/R MAppers are nice and their strengths can be found in development, maintenance productivity increases, Relational mapping through metadata (XML files), no tight coupling with the database, matches better with real life objects than the relational model.

But if raw performance and scalability are your main goal nothing <yet> beats "Stateless-ness" + stored procedures (ie.) which provide unequalled performance, control, and exposure to complete database functionality.

Justin
2004-11-28
re: oh sweet nectar of the gods... why have I not used an O/R mapper until now?!
"But if raw performance and scalability are your main goal nothing <yet> beats "Stateless-ness" + stored procedures (ie.) which provide unequalled performance, control, and exposure to complete database functionality."

Agreed, but when you are a one man shop a tool like an O/R mapper can make otherwise overwhelming projects doable. However the O/R mapper I'm using (LLBL Gen Pro) can make use of stored procedures.

Jay
2004-11-28
LLBLGenPro
Absolutely!, Have seen in some cases >= 50% improvements in develop productivity. If you could report back your ongoing experiences (good or bad) with LLBLGenPro - it would be appreciated. :)

>>statelessness + sp's

I have been doing some recent reading on this topic and Franz does make a compelling argument on this topic sp's in his blog.

http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx