We've been looking at using an ORM at work.
Currently we are trying to way up the pro's and con's of fluent nhibernate against castle active record.
开发者_如何学编程We are unsure of the flexibility of each as our database isn't very conventional. It lacks foreign keys and identities on the primary keys (A little confusing but the next value is stored in a seperate table). Also there are a few situations where we have table names suffix'd by the year. We then select from one depending on the year. This could obviously be a little trickier.
I've currently managed to sort the foreign key mapping using castle and also the primary key generation by create a custom class.
Does any one have any opnions on either of these frameworks and or ideas of how to solve these problems with either.
Ps. please don't ask us to refactor the database. Its not an option at the moment.
Thanks.
FluentNHibernate and ActiveRecord are quite different. The first one is just codified, convention driven mapping generator for NHibernate. The latter is a layer of abstraction on top of NHibernate along with implementation of the Active Record pattern.
Castle Active Record does hide certain aspects of NHibernate from you, taking care of some things by itself. As such it may be less flexible option if you already have a convoluted existing database.
FluentNHibernate just generates your mappings and you use NHibernate directly all the time to interact with your database.
So while I'm not the expert in any of these, I'd say for such convoluted DB you want to stay as close to the metal as possible, so perhaps bare NHibernate (mapped via FluentNHibernate or hbms where required), or even IBatis.NET would be a better option for you.
Where ActiveRecord shines, is when you start your project from scratch, with no legacy DB.
Here is a database first approach code generator, which supports Both Castle ActiveRecord and EntityFramework CodeFirst. Give it a try. http://salardbcodegenerator.codeplex.com/
An updated answer. Just in case someone is still considering Castle Active Record.
Castle ActiveRecord is obsolete. Meaning, that you cannot use it with NHibernate version >= 3.3.
精彩评论