Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate table for mapping IPAddress as INET type in PostgreSQL?

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

like image 422
Valentin Kuzub Avatar asked May 02 '12 07:05

Valentin Kuzub


Video Answer


1 Answers

Map(x => x.IPAddress)
    .CustomSqlType("inet")
    .CustomType<IPAddressToInetUserType>();  // maybe needed, you should check
like image 140
Firo Avatar answered Sep 30 '22 08:09

Firo