Npgsql provides a mapping between System.Net.IPAddress
and Postgres' inet
column type.
My EF Core configuration contains:
builder
.Property(p => p.IPAddress)
.HasColumnType("inet") // I want to avoid this magic string
.Required();
I know I can just leave it out, but I want to be explicit.
Does Npgsql have a constant, enum or type that I can use instead of hardcoding "inet"
?
(e.g. NpgsqlColumnTypes.IPAddress
which would equal "inet"
.)
You could open an NpgsqlConnection, access its TypeMapper
and enumerate on Mappings
on that - this should give you all the PostgreSQL types that Npgsql supports on that particular PostgreSQL.
However, that really shouldn't be necessary. It is standard practice to simply embed type names as strings. They are well-known stable names which never change.