12

I got a mapping that maps IPAddress object field to database.

There is inet type in PostgreSQL suited for this, but in my case it uses bytea type instead when it generates schema.

Is there a way to force resulting generated schema type for this column to be inet actually in DB?

I also happen to have this requirement on composite ID (whicg is required)

CompositeId()
.KeyProperty(x => x.Date, "for_date")
.KeyProperty(x => x.Address, var => var.ColumnName("ipaddress"));

You cant really use CustomSqlType on key property part.

I also tried using

public class IPAddressPropertyConvention : IPropertyConvention
{
    public void Apply(IPropertyInstance instance)
    {
        if (instance.Property.PropertyType == typeof(IPAddress))
            instance.CustomSqlType("inet");
    }
}

But I get exception about invalid property convention

Valentin Kuzub
  • 11,703
  • 7
  • 56
  • 93

1 Answers1

4
Map(x => x.IPAddress)
    .CustomSqlType("inet")
    .CustomType<IPAddressToInetUserType>();  // maybe needed, you should check
Firo
  • 30,626
  • 4
  • 55
  • 94
  • Is it a working solution or a supposedly working? Because it doesn't work for me I think. – Valentin Kuzub May 03 '12 at 07:48
  • this is the way to go when mapping custom types. it is working for for many other types hence it most probably works here too. **note: since it is a key property you need IIdConvention** – Firo May 03 '12 at 08:34
  • there is a similar case for hibernate https://forum.hibernate.org/viewtopic.php?f=1&t=984186 – Firo May 03 '12 at 08:35
  • read that thread, although its like 2 years old so thought maybe theres some progress in the area. – Valentin Kuzub May 03 '12 at 08:57