Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to implement NHibernate's IUserType.</p> <p>It should like this:</p> <pre><code>using NHibernate.SqlTypes; using NHibernate.UserTypes; [Serializable] //to allow NH configuration serialization public class GuidTypeConverter : IUserType { SqlType[] sqlTypes; public GuidTypeConverter() { sqlTypes = new[] { SqlTypeFactory.GetSqlType(DbType.Guid, 0, 0) }; } public SqlType[] SqlTypes { get { return sqlTypes; } } public Type ReturnedType { get { return typeof(Guid); } } public object NullSafeGet(IDataReader rs, string[] names, object owner) { if (rs[names[0]] == DBNull.Value) { return Guid.Empty; } return (Guid) rs[names[0]]; } public void NullSafeSet(IDbCommand cmd, object value, int index) { var param = (IDataParameter) cmd.Parameters[index]; param.DbType = sqlTypes[0].DbType; var guid = (Guid) value; if (guid != Guid.Empty) { param.Value = guid; } else { param.Value = DBNull.Value; } } public bool IsMutable { //guid is struct so it's not mutable get { return false; } } 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 cached; } public object Disassemble(object value) { return value; } public new bool Equals(object x, object y) { return x != null &amp;&amp; x.Equals(y); } public int GetHashCode(object x) { return x.GetHashCode(); } } </code></pre> <p>(Note that I haven't tested it, there are casts here - some tweaking is probably needed)</p> <p>In mapping you specify:</p> <pre><code>&lt;property name="GuidProperty" column="guidColumn" type="GuidTypeConverterNamespace.GuidTypeConverter, GuidTypeConverterAssemblyName" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload