-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to map inet column to (IPAddress, int) tuple #1158
Comments
Good catch, we currently map Sure, feel free to submit a PR adding support for this. To avoid duplication, this should be done by making the existing NpgsqlInetTypeMapping more flexible, and probably merging it with the existing NpgsqlCidrTypeMapping into a new merged mapping which would support IPAddress->inet, (IPAddress, int)->inet and (IPAddress, int)->cidr. The default for (IPAddress, int) should stay cidr to avoid a breaking change on this. |
Fixes npgsql#1158 Unified cidr and inet handling code since they're similar.
The mapping of inet/cidr as .NET value tuples is being removed in 8.0; instead, simply NpgsqlInet and NpgsqlCidr structs can be used. The work to support these has already been done (see #2882 and npgsql/npgsql#5136). |
I need to store an IP address along with its netmask in an
inet
column.I would like to map the value of the column to a tuple of type
(IPAddress, int)
, as I already do with columns of typecidr
.I tried to explicitly specify the column type, as in the following example:
However, adding the migration fails with the error
The property 'Entity.Address' is of type 'ValueTuple<IPAddress, int>' which is not supported by current database provider. Either change the property CLR type or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
The cause seems to be that a
RelationalTypeMapping
for the mapping betweeninet
and a tuple is not defined.The only
RelationalTypeMapping
that is defined for inet columns and configured inNpgsqlTypeMappingSource
is for the mapping betweeninet
andIPAddress
.I currently resolved with a custom type mapping source and an additional type mapper:
and in
Startup
:In this way, a property with type
(IPAddress, int)
is correctly mapped to theinet
column type when an attribute[Column(TypeName = "inet")]
is specified.Can I try to make a PR with this additional type mapper defined and configured in
NpgsqlTypeMappingSource
? Or are there some drawbacks that I have not considered?The text was updated successfully, but these errors were encountered: