Ha, i got it...
i wrote an own mapper. i want to use a boolean property in my entities, but in the database i want to save an integer (well, actually i dont want it, but the stupid DB2 canot handle bool).
In your entity: public virtual bool IsActive { get; set; }
in your mapper Map(x => x.IsActive).CustomType(typeof(BooleanType));
Write the own Type BooleanType public class BooleanType : IUserType { #region IUserType Member public bool IsMutable { get { return false; } }
public Type ReturnedType { get { return typeof(BooleanType); } }
SqlType baseType = new SqlType(System.Data.DbType.Int16); public SqlType[] SqlTypes { get { return new[] { baseType }; } }
public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner) { var obj = NHibernateUtil.Int16.NullSafeGet(rs, names[0]); if (obj == null) return null;
bool bolVal = Convert.ToBoolean(obj); return bolVal; }
public void NullSafeSet(System.Data.IDbCommand cmd, object value, int index) { if (value == null) { ((IDataParameter)cmd.Parameters[index]).Value = DBNull.Value; } else { bool bolVal = Convert.ToBoolean(value); ((IDataParameter)cmd.Parameters[index]).Value = bolVal ? 1 : 0; // Wenn true, dann eins (true), ansonsten 0 (false) }
}
public object DeepCopy(object value) { if (value == null) return 0; return value; }
public object Replace(object original, object target, object owner) { return original; }
public object Assemble(object cached, object owner) { return cached; }
public object Disassemble(object value) { return value; }
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();//x == null ? typeof(bool).GetHashCode() + 473 : x.GetHashCode(); }
#endregion
Well, i havent tested the reading yet, but thats a good start.
Hope that helps Nico
|