nhibernateusertypecompositeusertype

NHibernate CompositeUserType: How to specify Sql Types?


Using NH 2.0, I have a custom type. It is composed of four properties, so I implemented ICompositeUserType.

I want to specify length and precision for the string and decimal properties within the user type, to avoid specifying it with every usage in the mapping files.

But there is only a PropertyTypes property to implement, which returns IType. The funny thing is, the IUserType has a SqlTypes property, ICompositeUserType does not.

Thanks a lot.


Solution

  • I found the solution, it is pretty simple. I have to create the NHibernate types using the TypeFactory:

    public IType[] PropertyTypes
    {
      get
      {
        return new []
        {
          TypeFactory.GetDecimalType(36, 18),
          TypeFactory.GetStringType(100)
        }
      }
    }