Nhibernate: using ‘formula’ to map to a class

On one of the projects I work on I came across the need to use a function to calculate a property value.
 
The basic functionality is well documented in the online docs, however it doesn’t explicitly say what happens if the function returns DB PK (id) and you want it mapped to a class. It’s not even matter of "formula" as it is general matter of mapping.
 
Normally mapping to a class is done with <many-to-one> element, but that element doesn’t support "formula" attribute, nor does it have <loader> element.
Simple test shows that it works if you simply specify the "formula" and the "type" attributes. Apparently it works almost like many-to-one, with one notable difference: if value is null, many-to-one assigns null, while property seems to assign a new uninitialized instance. I can live with that.
 
All hail nhibernate!

 

Advertisements
Nhibernate: using ‘formula’ to map to a class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s