Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate: Adding DbTypes For Postgres

I am trying to register new DbTypes for custom user types, and it is only allowing me to use the asp.net DbTypes to associate custom user types that I have created.. for instance:

    /// <summary>
/// An SQL dialect for PostgreSQL 8.2 and above.
/// </summary>
/// <remarks>
/// PostgreSQL 8.2 supports <c>DROP TABLE IF EXISTS tablename</c>
/// and <c>DROP SEQUENCE IF EXISTS sequencename</c> syntax.
/// See <see cref="PostgreSQLDialect" /> for more information.
/// </remarks>
public class PostgreSQL82Dialect : PostgreSQL81Dialect
{
    public PostgreSQL82Dialect()
    {
        RegisterColumnType(DbType.Guid, "uuid");
        RegisterColumnType(DbType.Object, "uuid[]");
        RegisterColumnType(DbType.Object, "integer[]");
        RegisterColumnType(DbType.Binary, "jsonb");
    }

    public override bool SupportsIfExistsBeforeTableName
    {
        get { return true; }
    }

    public override string GetDropSequenceString(string sequenceName)
    {
        return string.Concat("drop sequence if exists ", sequenceName);
    }
}

I added uuid[], integer[] and jsonb. The only problem is when you try to do a schema update it always gets the last column type registered for any given dbtype. The problem with that is, there is no .net data type specified for arrays or blobs... so I have to use object for them. In this case, any custom user type that has a dbtype of object will always be an integer array in the database when I call schema update like so:

   var update = new SchemaUpdate(configuration);
   update.Execute(true, true);

Is there another way to let NHibernate know how to map these columns to the database?

Thanks in advance.

like image 586
The Pax Bisonica Avatar asked Jul 26 '26 04:07

The Pax Bisonica


1 Answers

You need to specify the sql-type in the mapping:

<property name="Foo" type="String">
    <column name="foo" length="64" not-null="true" sql-type="text"/>
</property>
like image 118
Oskar Berggren Avatar answered Jul 27 '26 18:07

Oskar Berggren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!