NHibernate or FluentNHibernate or ActiveRecord?

I'm in the process of mapping my CSharp classes to database tables. I decided to use NHibernate as an ORM tool after comparing with other tools. I have never done a real project with NHibernate before and am now looking into alternatives for mapping,

ActiveRecord: As per the project website, using ActiveRecord can significantly improve performance. However, I don't like the idea of ​​adding attributes to CSharp classes. After all, my class shouldn't have any knowledge of database relationships. Using ActiveRecord, I will link my perfectly separated classes to ActiveRecord and give me a hard time if I ever want to switch the DAO Layer implementation in the future.

FluentNHibernate: FluentNhibernate was my first attempt at starting mapping. But I also have a few problems with this approach. 1) I don't like my display strategies compiled as binaries. I would like to be able to change the display by changing the xml files. 2) Expiration date of FluentNHibernate. NHibernate has been around for a long time and has many users, so I'm quite happy with my maturity. In contrast, FluentNhibernate is relatively young and hasn't been tested by that many users. Even though I could dive into the source to fix any issue, I don't like my skills in touching low level implementation. 3) The availability of documentation for FluentNHibernate is much higher than for NHibernate. I wish I had a place to go when I hit a solid wall.

NHibernate: I am currently using naked Nhibernate xml to do the mapping. To be honest, working with XML is giving me a lot of headaches. Literally, I have to resist the urge to just throw away the .hbm.xml files and grab ActiveRecord or FluentNHibernate multiple times a day.

So here's my dilemma: should I go with my heart: "Just do it, damn it!"; Or, should I follow the Good Practice Guidelines to get pain now and have a relatively easy time later?

Any comments?

+2


source to share


1 answer


Please note that any ORM-related classes should not be treated as business object classes or impacted by your user interface. They should be considered part of your data layer. This template is not unique to ActiveRecord. In general, you want your business layer to know as little as possible about what the ORM is underneath, and you don't want your UI to know about your data layer. You also want to consider DTOs .

Fluent NHibernate solves the problem of having weakly typed XML, which can be error prone to the refactor.



While there may be downsides to accepting something like ActiveRecord, this seems like a suitable solution in your case.

The best reason for using .hbm.xml files is that you are going to generate code from your database (using something like CodeSmith ). Manual encoding of .hbm.xml files is rarely the best option.

+4


source







All Articles