Closed uhfath closed 3 years ago
I can see the issue, but which version of the provider are you using?
Sorry, forgot to mentioned that. I'm using 5.0.10
@uhfath thanks for flagging this - I've fixed this for 5.0.11. In the meantime, you can use the daily build version 5.0.11-ci.20211004T154222 (or above) from the patch nuget feed.
@roji thanks for taking the time to look into this. Worked flawlessly. However, I've noticed that SQL command that got generated is exactly the same, but it worked this time. How is that? Or is it just some metadata that was passed along with a command that changed?
@uhfath the problem was with the internal mapping inside the provider, which caused us to accidentally send a tstzrange
(range of timestamp with time zone
) instead of a daterange
(range of date
). The .NET type for both these is the same (NpgsqlRange<DateTime>
), but on the PostgreSQL side these are two very different types which don't implicitly convert to one another.
BTW if you're interested in date ranges, #2016 will allow you to map NpgsqlRange<DateOnly>
(DateOnly is a new type being introduced .NET 6, which cleanly represents only a date). And if you're open to using NodaTime (which I can't recommend enough), you will even be able to use DateInterval, which maps very nicely to PostgreSQL daterange.
You can take 6.0.0-rc.1 for a spin if you'd like - DateInterval already works there (but NpgsqlRange<DateOnly>
doesn't yet work).
Thanks for the info.
Yeah, I'm waiting for DateOnly
to see how it works out.
As for NodaTime, it's being on my radar for already long time (pun intended), but just didn't have a chance to look at it closely enough.
Perhaps later, but thanks for the suggestion.
I'm getting the same error using the latest patch 5.0.11-ci.20211004T154222. Is the explicit attribute [Column(TypeName = "daterange")]
required? The doc doesn't mention it.
Adding the attribute makes it work.
@pokorsky I'm unable to reproduce this problem with the latest patch daily build (5.0.11-ci.20211004T154222) - with the code below, I can use NpgsqlRange<DateTime>
just fine even without the explicit column type name:
By default
NpgsqlRange<DateTime>
seems to map totsrange
. But I need it to bedaterange
.Here is my model:
During migration this maps correctly:
But the issues arise when using it like this:
This maps to (note the time part):
And as a result:
So how do I properly map my column to
daterange
? First thought was to use User-defined ranges but I'm not sure how to map totsrange
in other entities.BTW, docs mention that this should be mapped to
daterange
already.