Hello,
I'm writing a web application using ASP.net MVC, NPgsql and NHibernate with PostgreSQL as the database (using VB... not my choice).
One of the tables has two columns with an inet type. In the mapping file, I tried mapping it as a string. This actually worked fine until I had to update a row.
I get an error message: "column "mycolumn" is of type inet but expression is of type text."
I realized that Npgsql wants either an IPAddress object or a NpgsqlInet object. The NpgsqlInet object has a constructor that accepts a string, so I tried to create a custom user type following these instructions:
http://intellect.dk/post/Implementing-custom-types-in-nHibernate.aspx
The get works fine:
Public Function NullSafeGet(ByVal rs As System.Data.IDataReader, ByVal names() As String, ByVal owner As Object) As Object Implements NHibernate.UserTypes.IUserType.NullSafeGet
Dim ip As NpgsqlInet = New NpgsqlInet(CType(NHibernateUtil.String.NullSafeGet(rs, names(0)), String))
Return ip
End Function
As you can see, I pull it from the database as a String and use that as the parameter of the constructor.
But I'm getting stuck on the NullSafeSet method. I can't use the NHibernateUtil.String.NullSafeSet method because Npgsql wants the object as a NpgsqlInet type.
Any ideas?