tags:

views:

142

answers:

1

I'm having a problem in mapping an existing data class member to the database..

I have a database table where one of the columns is a string type, but actually stores a comma separated list of numbers. My data class shows this field as a list of integers.

The problem is that I couldn't find any hook in NHibernate that allows me to invoke the custom code that is required to replace the string field by the list and vice versa.

To illustrate (simplified of course):

The database table:

CREATE TABLE dummy (
    id serial,
    numlist text -- (can store values such as '1,2,3')
)

The data class:

class Dummy {
    public int Id;
    public List<int> NumbersList;
}

Can anyone help?

+1  A: 

Map the column as a NHibernate.UserTypes.IUserType.

<class name="Dummy">
    <property name="NumbersList" type="mynamespace.MyIntListType, mydll"  />
</class>

Some examples of IUserType:

Lachlan Roche
Thanks. After seeing your response I've googled this in nhforge website and found the relevant information there (http://nhforge.org/blogs/nhibernate/archive/2009/10/15/mapping-different-types-iusertype.aspx)
Liron Levi