You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users can create arbitrary range types, but Npgsql's EF Core type mapper currently doesn't look at the database to construct the mappings (singleton), making it impossible to know the datatype name for a given NpgsqlRange. What we can do is support the built-in range types, which will probably be enough.
dotnet/efcore#7269 was only blocking for scaffolding support, which isn't very critical. If I remember correctly I already added support for built-in range types (e.g. int4range, daterange...) to the current dev branch, so if you're feeling brave you can try to compile the provider yourself and use ranges (would love to hear about it).
Non-built-in ranges (which you can create with CREATE TYPE) aren't supported yet and would require a more significant refactor in how type mapping works.
I didn't manage to release this for 2.0.0, but I do hope to do this for the upcoming 2.1.0 release (for built-in types only at this stage). Anyone who's interested should upvote to let me know you need it, in case I don't have time to do everything on the plan.
Reacted by Oleg Anashkin, Colin Thompson, Dominik Psenner, Sebastian Zanoni, Patrick Neulichedl, Jarrod Mosen, Bryan Lee and anand
This is done and will be probably be released with 2.1.0-preview1.
Note that this only includes the 6 built-in range types, and not range types created by the user. It also doesn't map any operations yet - it only allows you to have NpgsqlRange<T> on your entities and have that correctly mapped to the database. For mapping range operations I've opened #311 - it shouldn't be too hard and may even make it for 2.1.
The only problem is that currently the EF Core provider only supports the built-in types, which don't including the floating-point types (see #329 for adding user-defined ranges and why it's not trivial). In the meantime, I don't think it makes sense to automatically map CLR float/double to PostgreSQL numeric, since these are quite different types, and since one day we may actually support user-defined ranges at which point things will probably break. The conversion between range and range would have to be supported at the Npgsql level, which I really don't want to do.
Besides, with the new value converters coming in 2.1 it should be pretty trivial to write a conversion between the two types...
@roji It appears to me that the mapping of DateTimeOffset was forgotten in the implementation, am I right?
I ask because we chose to explicitly map any timestamp to DateTimeOffset in an attempt to avoid timestamp skews caused by typos of DateTime.Now where it should read as DateTime.UtcNow because DateTimeOffset.Now behaves like DateTimeOffset.UtcNow. DateTimeOffset also provides better synergies for integration with grpc / protobuf. With the implementation given we are forced to use DateTime over DateTimeOffset and thus mix concepts in the application code.
@dpsenner first, regarding your decision to use DateTimeOffset in order to avoid timezone issues, I'm not a big fan :) See the following long rants if you're interested: #303, #473.
Regarding support of ranges over timestamptz, the discussion took place in #561.
Future readers, please ignore my comment above. If you are reading this you should consider to use timestamp over timestamptz along with NodaTimeInstants in your model. This makes your application layer responsible for dealing with timezoned information and that's the best place to have that logic. Note that reporting tools deliberately choose to discard any interpretations of timestamptz columns, effectively making them utc timestamps. People should think about how to store and interpret application data that comes from and goes to multiple timezones.
Activity
[-]Scaffold range types[/-][+]Support for built-in PostgreSQL ranges[/+]roji commentedon Dec 18, 2016
Scaffolding depends on dotnet/efcore#7269
wub commentedon May 1, 2017
dotnet/efcore#7269 is done now - is there anything else blocking this?
Thanks for all the hard work, @roji. If it weren't for npgsql I probably wouldn't be using .NET Core!
roji commentedon May 5, 2017
dotnet/efcore#7269 was only blocking for scaffolding support, which isn't very critical. If I remember correctly I already added support for built-in range types (e.g. int4range, daterange...) to the current dev branch, so if you're feeling brave you can try to compile the provider yourself and use ranges (would love to hear about it).
Non-built-in ranges (which you can create with
CREATE TYPE) aren't supported yet and would require a more significant refactor in how type mapping works.1 remaining item
SirGordon commentedon Aug 25, 2017
Is it shipped with 2.0? Trying to add migration with a field
[Column("length")] public NpgsqlRange<int> Length { get; set; }But I get
dpsenner commentedon Feb 15, 2018
bump The issue is still open but has milestone 2.0.0. Will it be shipped with the next release or is it going to be delayed?
roji commentedon Feb 17, 2018
I didn't manage to release this for 2.0.0, but I do hope to do this for the upcoming 2.1.0 release (for built-in types only at this stage). Anyone who's interested should upvote to let me know you need it, in case I don't have time to do everything on the plan.
dpsenner commentedon Feb 21, 2018
That's great news to hear! Looking forward to see 2.1.0 happen!
roji commentedon Feb 22, 2018
This is done and will be probably be released with 2.1.0-preview1.
Note that this only includes the 6 built-in range types, and not range types created by the user. It also doesn't map any operations yet - it only allows you to have
NpgsqlRange<T>on your entities and have that correctly mapped to the database. For mapping range operations I've opened #311 - it shouldn't be too hard and may even make it for 2.1.Map built-in range types
Map built-in range types
austindrenski commentedon Mar 7, 2018
Is it possible to include mappings for
NpgsqlRange<float>andNpgsqlRange<double>tonumrange?https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/blob/a67d76659594ae45cc0d9d95459a793e06b2bd45/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs#L97-L105
roji commentedon Mar 8, 2018
@austindrenski, PostgreSQL actually supports defining your own range types, and it's very easy to define on over floating-point types (see the example in the PostgreSQL docs).
The only problem is that currently the EF Core provider only supports the built-in types, which don't including the floating-point types (see #329 for adding user-defined ranges and why it's not trivial). In the meantime, I don't think it makes sense to automatically map CLR float/double to PostgreSQL numeric, since these are quite different types, and since one day we may actually support user-defined ranges at which point things will probably break. The conversion between range and range would have to be supported at the Npgsql level, which I really don't want to do.
Besides, with the new value converters coming in 2.1 it should be pretty trivial to write a conversion between the two types...
austindrenski commentedon Mar 8, 2018
That makes sense. Thanks for providing some context, much appreciated!
dpsenner commentedon Aug 2, 2018
@roji It appears to me that the mapping of
DateTimeOffsetwas forgotten in the implementation, am I right?I ask because we chose to explicitly map any timestamp to
DateTimeOffsetin an attempt to avoid timestamp skews caused by typos ofDateTime.Nowwhere it should read asDateTime.UtcNowbecauseDateTimeOffset.Nowbehaves likeDateTimeOffset.UtcNow.DateTimeOffsetalso provides better synergies for integration withgrpc/protobuf. With the implementation given we are forced to useDateTimeoverDateTimeOffsetand thus mix concepts in the application code.roji commentedon Aug 2, 2018
@dpsenner first, regarding your decision to use
DateTimeOffsetin order to avoid timezone issues, I'm not a big fan :) See the following long rants if you're interested: #303, #473.Regarding support of ranges over
timestamptz, the discussion took place in #561.dpsenner commentedon Aug 6, 2018
Future readers, please ignore my comment above. If you are reading this you should consider to use
timestampovertimestamptzalong withNodaTimeInstants in your model. This makes your application layer responsible for dealing with timezoned information and that's the best place to have that logic. Note that reporting tools deliberately choose to discard any interpretations oftimestamptzcolumns, effectively making them utc timestamps. People should think about how to store and interpret application data that comes from and goes to multiple timezones.