For now, I went with a custom type that allows me to use
Map(p=>p.doubleProperty).CustomType<DoubleString>();
What will do for my current needs.
Now I will leave the question open if someone comes up with an easier solution.
The code for the DoubleString type is below.
public class DoubleString : IUserType { public new bool Equals(object x, object y) { if (ReferenceEquals(x, y)) { return true; } if (x == null || y == null) { return false; } return x.Equals(y); } public int GetHashCode(object x) { return x.GetHashCode(); } public object NullSafeGet(IDataReader rs, string[] names, object owner) { var valueToGet = NHibernateUtil.String.NullSafeGet(rs, names[0]) as string; double returnValue = 0.0; double.TryParse(valueToGet, out returnValue); return returnValue; } public void NullSafeSet(IDbCommand cmd, object value, int index) { object valueToSet = ((double)value).ToString(); NHibernateUtil.String.NullSafeSet(cmd, valueToSet, index); } public object DeepCopy(object value) { return value; } public object Replace(object original, object target, object owner) { return original; } public object Assemble(object cached, object owner) { return DeepCopy(cached); } public object Disassemble(object value) { return DeepCopy(value); } public SqlType[] SqlTypes { get { return new[] { new SqlType(DbType.String) }; } } public Type ReturnedType { get { return typeof(double); } } public bool IsMutable { get { return true; } } }
source share