I use Nhibernate, C# and DB/2 and I had the same problem. Couldn't find any C# code so I followed the example in NHibernate.DomainModel.DoubleStringType and that's what I came up with (however, I take no responsibility for the code), but it works so far.
Code:
using System;
using System.Data;
using NHibernate;
namespace SomeNamespace
{
public class TrimmedString: NHibernate.UserTypes.IUserType
{
public TrimmedString()
{
}
public new bool Equals(object x, object y)
{
if (x == y) return true;
if (x == null || y == null) return false;
return x.Equals(y);
}
public object DeepCopy(object obj)
{
if (obj == null) return null;
return new String(((string)obj).ToCharArray());
}
public int GetHashCode(object obj)
{
return obj.GetHashCode();
}
public bool IsMutable
{
get { return false; }
}
public object NullSafeGet(
System.Data.IDataReader rs, string[] names, object owner)
{
string str = (string) NHibernateUtil.String.NullSafeGet(rs, names[0]);
if (str == null)
return null;
else
return str.[color=red]TrimEnd()[/color];
}
public void NullSafeSet(System.Data.IDbCommand cmd, object value, int index)
{
NHibernateUtil.String.NullSafeSet(cmd, value, index);
}
public Type ReturnedType
{
get { return typeof(string); }
}
public global::NHibernate.SqlTypes.SqlType[] SqlTypes
{
get
{
global::NHibernate.SqlTypes.SqlType[] types = new global::NHibernate.SqlTypes.SqlType[1];
types[0] = new global::NHibernate.SqlTypes.SqlType(DbType.String);
return types;
}
}
public object Assemble(object cached, object owner)
{
return DeepCopy(cached);
}
public object Disassemble(object value)
{
return DeepCopy(value);
}
public object Replace(object original, object target, object owner)
{
return DeepCopy(original);
}
}
}
Hope it helps...