Implement IUserType, this is some code i made but never used so i can't be sure its working but give it a shot:
Code:
public class UriType : IUserType
{
public object NullSafeGet(IDataReader rs, string[] names, object owner)
{
//TODO: Handle badly formatted URI's
Uri result = new Uri((string)NHibernateUtil.String.NullSafeGet(rs, names[0]));
return result;
}
public void NullSafeSet(IDbCommand cmd, object value, int index)
{
if (value == null)
{
NHibernateUtil.String.NullSafeSet(cmd, null, index);
return;
}
value = ((Uri)value).ToString();
NHibernateUtil.String.NullSafeSet(cmd, value, index);
}
public object DeepCopy(object value)
{
if (value == null) return null;
return new Uri(value.ToString());
}
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
{
SqlType[] types = new SqlType[1];
types[0] = new SqlType(DbType.String);
return types;
}
}
public System.Type ReturnedType
{
get { return typeof(Uri); }
}
public bool IsMutable
{
get { return false; }
}
public bool Equals(object x, object y)
{
if (x == null || y == null) return false;
return x.ToString().Equals(y.ToString());
}
public int GetHashCode(object x)
{
return x.GetHashCode();
}
}
You can now map:
Code:
public Uri MyUri{ get; set; }
with:
Code:
<property name="MyUri" type="Your.Namespace.UriType , Your.Assembly" />