Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>NHibernate does not know how to deal with complex types like TcpClient out of the box. But it lets you provide your own loading and storing code. You can use <a href="http://intellect.dk/post/Implementing-custom-types-in-nHibernate.aspx" rel="nofollow">IUserType</a>:</p> <pre><code>public class TcpClientMapper : IUserType { public SqlType[] SqlTypes { get { return new[] { new SqlType(DbType.String), new SqlType(DbType.Int32) }; } } public Object NullSafeGet(IDataReader rs, String[] names, ...) { String address = NHibernateUtil.String.NullSafeGet(rs, names[0]); Int32 port = NHibernateUtil.Int32.NullSafeGet(rs, names[1]); return new TcpClient(address, port); } public void NullSafeSet(IDbCommand cmd, Object value, Int32 index) { TcpClient tcpClient = value as TcpClient; if(tcpClient == null) { NHibernateUtil.String.NullSafeSet(cmd, null, index); NHibernateUtil.Int32.NullSafeSet(cmd, null, index + 1); } else { EndPoint red = tcpClient.Client.RemoteEndPoint; IPEndPoint endpoint = ((IPEndPoint)red); NHibernateUtil.String.Set(cmd, endpoint.Address.ToString(), index); NHibernateUtil.Int32.Set(cmd, endpoint.Port, index + 1); } } public Type ReturnedType { get { return typeof(TcpClient); } } // TODO: implement other methods } </code></pre> <p>And map it like this in hbm:</p> <pre><code>&lt;property name="_tcpClient" type="MyNamespace.TcpClientMapper, MyAssembly"&gt; &lt;column name="Address" /&gt; &lt;!-- NullSafeGet/Set index == 0 --&gt; &lt;column name="Port" /&gt; &lt;!-- NullSafeGet/Set index == 1 --&gt; &lt;/property&gt; </code></pre> <p>Or use fluent <a href="http://wiki.fluentnhibernate.org/Available_conventions" rel="nofollow">UserTypeConvention</a>:</p> <pre><code>public class TcpClientUserTypeConvention : UserTypeConvention&lt;TcpClientMapper&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