生成用于在PostgreSQL中将IPAddress映射为INET类型的表?

Val*_*zub 12 c# postgresql nhibernate fluent-nhibernate

我有一个映射将IPAddress对象字段映射到数据库.

inetPostgreSQL中有类型适合这种类型,但在我的情况下,它bytea在生成模式时使用类型.

有没有办法强制此列生成的模式类型inet实际上在DB中?

我也碰巧对复合ID有这个要求(需要whicg)

CompositeId()
.KeyProperty(x => x.Date, "for_date")
.KeyProperty(x => x.Address, var => var.ColumnName("ipaddress"));
Run Code Online (Sandbox Code Playgroud)

你真的不能在key属性部分使用CustomSqlType.

我也试过用

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

但我对无效的属性约定有例外

Fir*_*iro 4

Map(x => x.IPAddress)
    .CustomSqlType("inet")
    .CustomType<IPAddressToInetUserType>();  // maybe needed, you should check
Run Code Online (Sandbox Code Playgroud)