Andrew Stopford's Weblog

poobah

News

Articles

MbUnit Folks

Old Blogs

ActiveRecord is the answer

In my last post I pondered how a ORM and Sprocs fit in, for me a database that is in at least 4nf and has 1 to many relations with the data is going to need joins in it's queries and its really the issue of the mechs of a decent TSQL sproc that was chewing me the most (queries with joins, in's etc).

When I mentioned this to a friend we started discussing Rails and ActiveRecord and it was with the edition of AR on-top of a ORM that it all become clear. With AR you have a high level of obstraction to define how your ORM mapped objects relate.  The AR and ORM create the queries and joins for you, an example here and another example here (as a side here's an interesting post on why AR in Rails matches, or not, to CF). Going back to the .NET world the only AR\ORM implementation I know of is the mighty Castle project's ActiveRecord which maps a AR pattern to the NHiberinate ORM. Not sure if you can do the same sort of thing in terms of joins, in's etc with Castle as you can with Rails, prehaps the Castle guys could comment.

Posted: Aug 24 2006, 10:05 AM by astopford | with 8 comment(s)
Filed under: ,

Comments

Colin Ramsay said:

Castle Active Record gives you access to all of the query stuff in NHibernate if you want it. So whatever features are in Hibernate, you've got them in Castle Active Record.

# August 24, 2006 6:07 AM

Ayende Rahien said:

You can do quite a bit with AR, including joins, etc.

The framework is smart enough to know about the associations between objects and query for them effectively.

# August 24, 2006 6:19 AM

Andrew Stopford said:

Ayende, any examples that show this ?

# August 24, 2006 6:33 AM

Scott said:

They have an excellent page describing the many ways you can map your objects to your data

http://www.castleproject.org/index.php/ActiveRecord:Mappings

# August 24, 2006 5:35 PM

Will said:

# August 24, 2006 5:52 PM

Tim Barcz said:

There are several features you can use.  HasMany, BelongsTo, HasManyAndBelongTo (for many to many relationships).

I recently looked at ActiveRecords and with the options provided (ie lazy loading) you can really get what you want, when you want it.

I applaud the Castle people though I have yet to use their AR in a real world setting, we're considering it for some upcoming stuff.

# August 25, 2006 12:56 PM

byron walker said:

Hi Andrew,

I have used both AR and nHib, and I moved away from AR because that pattern proved more difficult to test (mock) than using nHib directly.

The reason for using AR was the abstraction and no XML files, both very bad reasons NOT to use nHib.

Although Ayende did solve the AR testability issue, nHib is much cleaner and doesnt mess with your domain model like the AR pattern does.

# August 28, 2006 8:12 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)