views:

217

answers:

2

Hi,

My domain model is using System.Net.Uri to represent URLs, and System.Drawing.Color to represent colors. In the db, uris are simply nvarchars and colours are web (hex) rgb values.

Using NHibernate, is there some way to map between these values using some custom mapper?

I don't need to query against these items, but it would be nice if I could.

Any help is greatly appreciated.

A: 

You could use Transformers. I used them for a native query which transforms the result to a custom object. In your case you could adjust the get properties to transform to your Uri and Color representation.

Henrik
+3  A: 

What you need are user types. Implement IUserType or IComplexUserType (there are some more interfaces to match other needs).

There are some examples:

Using the user type, you can map any class to any number of columns of any type. Implementing the user type means implementing the mapping between them.

The mapping could look like this:

<property "MyColor" type="ColorUserType">
  <column name="R"/>
  <column name="G"/>
  <column name="B"/>
</property>
Stefan Steinegger
Wunderbar! Worked perfectly! NHibernate is getting better everyday.. It was such a pain to do stuff like this in linq to sql
CVertex
:-) I think this is quite an old feature. The problem is that NH has many features, but sometimes it is not easy to find them.
Stefan Steinegger