1

We are in the process of refactoring an ASP.NET WebForms application to ASP.NET MVC (3). We defined our mappings in the usual ClassName.hbm.xml format. But now we find that this seems a little redundant with the attributes you can specify on the class properties with MVC.

Is there a nice and clean way of telling NHibernate to use the attributes to buid the mappings, instead of using the XML files?

Astaar
  • 5,858
  • 8
  • 40
  • 57

2 Answers2

4

Take a look at fluent Nhibernate. You can use this to configure your mappings through code with minimal effort. You can also use it read attributes declared on your classes and set up mappings appropriately (see http://mookid.dk/oncode/archives/139 for an example)

WiseGuyEh
  • 18,584
  • 1
  • 20
  • 20
2

The "semi-official" way to map using attributes is NHibernate.Mapping.Attributes, a contrib project.

There's also Castle.ActiveRecord, which is actually flexible enough not to force you into using the ActiveRecord pattern so you can use it mostly for mapping with its attributes only.

Fluent NHibernate has already been mentioned.

Another mapping tool is ConfORM (somewhat similar to Fluent NHibernate), created by the current NHibernate dev lead.

A couple of previous questions comparing Fluent NHibernate to attribute mapping:

Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275