I would implement an ICompositeUserType for a string property, that is splitted in 4 columns of 2000 chars (in a legacy oracle database, to avoid CLOB/LONG fields). Implementing the interface seems to be a good idea, but I can't understand the SetPropertyValue method. It doesn't accepts typed or string values. And I need it as mutable, so I need to implement this method.
I could have a non persistent property that encapsulates the split and join to x persitent properties, but I want something more transparent.
I've found similar questions but none responses as I expected.
-- UPDATE--
I upload some code to add context to the question:
DATABASE:
...
Value VARCHAR2(2000 BYTE)
Value2 VARCHAR2(2000 BYTE)
Value3 VARCHAR2(2000 BYTE)
Value4 VARCHAR2(2000 BYTE)
Value5 VARCHAR2(2000 BYTE)
...
HBM:
<property name="Value" type="MyAssembly.NHibernateUtils.Types.MultiColumnJoinedUserType, MyAssembly">
<column name="DFM_Value"/>
<column name="DFM_Value2"/>
<column name="DFM_Value3"/>
<column name="DFM_Value4"/>
<column name="DFM_Value5"/>
</property>
CLASS:
public virtual string Value { get; set; }
MultiColumnJoinedUserType:
/// <summary>
/// Set the value of a property
/// </summary>
/// <param name="component">an instance of class mapped by this "type"</param>
/// <param name="property"></param>
/// <param name="value">the value to set</param>
public void SetPropertyValue(object component, int property, object value) { ... }
In my class the component field of the method is a string, so it's impossible to change its value without changing the reference, because string is passed as value not as reference as I need.
I spend some hours in this issue and various solutions tried:
Both worked in Oracle, but in SQL (I need the compatibility) the null values are set as default insted of null.
NHibernate trace in log4net:
But in SQLProfiler:
I've tried various pieces of code on nullsafeset (use DBNull, string.NullSafeSet, ...) but nothing works for me. I can't waste more time and finally I've implemented the simplest solution, 5 "hidden" properties on mapped object and a "virtual" property that splits and joins the values, it isn't very transparent but it works as expected:
That's enough for me in this moment.