views:

158

answers:

2

I know annotations to do the hibernate mapping in Java and am looking now for a similar way to do the same in C# and NHibernate. I found out that there exists several approaches

  • do the mapping in xml files
  • NHibernate.Mapping.Attributes (NHMA)
  • Fluent
  • are there any more??

I tried NHMA and found out it had some blocking points for me...

I don't want you to discuss, whats the best way to map models to NHibernate, but I was looking for a good comparison on the internet.

Do you know such sites? What facts are the main points to consider, if I choose one of the "frameworks" listed above? I'm thinking of aspects like 'is this project offically supported by the NH-Developers?', 'are there models that can be mapped in xml-mapping but not in fluent/NHMA/etc...?'

What can you recommend? Why?

+2  A: 

Fluent NHibnernate auto mapping or code generation (CodeSmith, MyGeneration, T4, etc.) are the most productive ways to create the mapping files. I dislike the attributes approach because I like to keep my POCOs plain.

Jamie Ide
+1 Have to go fluent to keep POCOs clean and to avoid nasty XML problems when objects are altered.
Stephen Newman
+1  A: 

Another option, if you don't mind attributes, is Castle ActiveRecord.

Here's an article that might help you decide.

Mauricio Scheffer
I apreciate your post. Thanks for the article. I dont't mind attributes in my model, but I don't want every entity to inherit a base class out of the ActiveRecord framework. And I dont't want my entities to take care of their own storage. Like a DAO better ;)
paologios
Inheriting from ActiveRecordBase<T> is entirely optional. As a DAO you can use ActiveRecordMediator or a wrapper like Ayende's IRepository: http://github.com/ayende/rhino-tools/blob/master/commons/Rhino.Commons.ActiveRecord/Repositories/ARRepository.cs
Mauricio Scheffer

related questions