by Arthur Correa on 1/13/2010
Share on Twitter or Facebook

So back in August I mentioned that I was being slow in posting because I was making the switch to NHibernate.  Well I finished that conversion about a week after that post, so what's my excuse now?

At any rate lets talk about NHibernate.  First of all.  I used it in conjunction with Castle's Active Record project.  It was a really quick and clean implementation.  I converted over from LINQ2SQL in about a weekend with the worst of the changes being some minor tweaks to my Repository classes over some LINQ object naming quirks.  The fact that I had placed a Repository layer between my Services and my data store really helped with this since I had a logical place to store all my CRUD logic that was independant of my ORM classes.

From a development point of view everything worked out great, a few attributes and my data was loading and saving cleanly.  Now as I mentioned I'm using a Repository pattern in my Data Layer and you may have noticed that I didn't mention making a switch to the ActiveRecord patter to make full use of Castle's implementation  That was intentional, because all I wanted the Castle libs for was the attributes on the classes to map the ORM, and for session scoping to a single request (they provide an httpModule to simplfiy this).

So I went ahead and deployed these changes back in August, and immediately noticed a pretty big impact in performance.  What the heck?   Well it turns out that NHibernate/Castle will load all the objects in a hierarchy by default, the default is not to lazy load.  So with every page request a LOT of data was getting loaded.  Ok no big deal I just set the Castle Attribute to LazyLoad=true on my relationships.  Went smooth went easy, and when I deployed it went kerplunk-kerplooey.

Grrr!  Ok, now what's t the problem.  Well apparently in my hosted GoDaddy environment I apparently run in medium trust, which causes problems for the Castle lazy loading.  So after a little research I found this link.  It kind of sucks that I had to download and rebuild my dll's to allow for partially trusted callers, but with a little bit of effort I got it all squared away, and its all working like a champ.

So how do I like it?  Well for starters I like it better then LINQ2Sql, I find I like the syntax to query the database much easier to use than the lambda expressions used with LINQ2Sql.  I've actually used this same implementation on two different projects since converting this site over, and recommended it for a third project that someone I know is working on.



by {{ comment.AuthorName }} on {{ comment.DefaultDateStringFormat }}
{{ comment.Text }}

* This is not a valid email.
This is not a valid url.