After see some characteristic of one of the new NHibernate 3.2 feature it’s the time to see if the mapping by-code gives support to a convention based mapping. In NHibernate there isn’t a real difference between declarative-mapping and convention-based-mapping because every thing live together since the first commit.
What you will see in this post is defined, by some people, as “auto-mapping”. We don’t have such pretention, and we don’t need to sell something so we are far away to call it auto-mapping but you are free to call it as you want.
For the coming soon version we took the decision to avoid to override the tables/columns naming-convention provided by NHibernate XML mapping; the same for cascade.
The domain model
The model was provided by a NHibernate user: Luka (cluka23)
Well… not so complicated but even not so simple
Luka have sent me the conformist-mapping so I can understand which is his target. Only to have a little bit of fun I have added two fields for two collections (see class Application). The whole mapping with conventions and registration in NHibernate’s configuration is:
Line 4: predicate to recognize entities.
Line 5: predicate to recognize root entities.
From line 7 to 10: some conventions.
From line 12 to 16: some specific mapping of some properties strongly mapped using the base Entity class
From line 18 to 26: some specific mapping of some properties for others entities
Line 28: the creation of the mapping for the whole domain
Line 30: registration of the mapping in the NHibernate configuration.
As you can see there isn’t something special to override conventions, it is all the same you can use with explicit mapping.
If you can’t resist to have a specific class to override a convention you can use something like this:
“Ehy!! Fabio, you are wrong!! that class is for conformist-mapping.” No, I’m not wrong. You can use the same identical classes to override your conventions, the same classes you can use for declarative mapping. Not only this but can even mix altogether:
“and the two fields ?” those two fields was mapped, don’t worry. If you want see a chuck of the XML:
NHibernate 3.2 too sexy by far!!!