Hi Scottpkuehn,
I have done this before, but I had to use a custom user-type. Here's the code (N.B., it's only been tested against string and int just now, you'd need to test other types yourself.
The property to be mapped to was declared as an obect. The database I was using was SQL server.
The mapping was:
Code:
<property name="ObjectProperty" column="variant_column" type="MyNamespace.SqlVariant, MyAssembly" />
... and the user-type class was:
Code:
public class SqlVariant : IUserType
{
private SqlType[] variantSqlType = new SqlType[1] { new SqlType(DbType.Object) };
public SqlType[] SqlTypes
{
get
{
return variantSqlType;
}
}
public System.Type ReturnedType
{
get { return typeof(object); }
}
public new bool Equals(object x, object y)
{
return object.Equals(x, y);
}
public int GetHashCode(object x)
{
return x.GetHashCode();
}
public object NullSafeGet(IDataReader rs, string[] names, object owner)
{
int ordinal = rs.GetOrdinal(names[0]);
if (rs.IsDBNull(ordinal))
{
return null;
}
else
{
return rs[ordinal];
}
}
public void NullSafeSet(IDbCommand cmd, object value, int index)
{
object valueToSet = (value == null) ? DBNull.Value : value;
((IDbDataParameter) cmd.Parameters[index]).Value = valueToSet;
}
public object DeepCopy(object value)
{
return value;
}
public bool IsMutable
{
get { return false; }
}
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;
}
}
Hope that helps.
Regards,
Richard