Я бы пошел с типом пользователя
class UInt64UserType : ImmutableUserType
{
public object NullSafeGet(IDataReader rs, string[] names, object owner)
{
var value = NHibernateUtil.Decimal.NullSafeGet(rs, names[0]);
return (value == null) ? 0 : Convert.ToUInt64(value);
}
public void NullSafeSet(IDbCommand cmd, object value, int index)
{
decimal d = Convert.ToDecimal(value);
NHibernateUtil.Decimal.NullSafeSet(cmd, d, index);
}
public Type ReturnedType
{
get { return typeof(UInt64); }
}
public SqlType[] SqlTypes
{
get { return new[] { SqlTypeFactory.Decimal }; }
}
}
.CustomType<UInt64UserType>()
Редактировать: извините, забыл заметить.У меня много пользовательских типов, поэтому я реализовал свои собственные базовые классы
public abstract class ImmutableUserType : UserTypeBase
{
public override bool IsMutable
{
get { return false; }
}
public override object DeepCopy(object value)
{
return value;
}
public override object Replace(object original, object target, object owner)
{
return original;
}
public override object Assemble(object cached, object owner)
{
return cached;
}
public override object Disassemble(object value)
{
return value;
}
}
public abstract class UserTypeBase : IUserType
{
public new virtual bool Equals(object x, object y)
{
return EqualsHelper.Equals(x, y);
}
public virtual int GetHashCode(object x)
{
return (x == null) ? 0 : x.GetHashCode();
}
public abstract object Assemble(object cached, object owner);
public abstract object DeepCopy(object value);
public abstract object Disassemble(object value);
public abstract bool IsMutable { get; }
public abstract object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner);
public abstract void NullSafeSet(System.Data.IDbCommand cmd, object value, int index);
public abstract object Replace(object original, object target, object owner);
public abstract Type ReturnedType { get; }
public abstract SqlType[] SqlTypes { get; }
}