daterange is mapped incorrectly
See original GitHub issueBy default NpgsqlRange<DateTime>
seems to map to tsrange
.
But I need it to be daterange
.
Here is my model:
public class ServiceRate
{
[Key]
public int Id { get; set; }
[Column(TypeName = "daterange")]
public NpgsqlRange<DateTime> Period { get; set; }
}
During migration this maps correctly:
migrationBuilder.CreateTable(
name: "ServiceRates",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityAlwaysColumn),
Period = table.Column<NpgsqlRange<DateTime>>(type: "daterange", nullable: false),
},
constraints: table =>
{
table.PrimaryKey("PK_ServiceRates", x => x.Id);
});
But the issues arise when using it like this:
dbContext.ServiceRates.Add(new ServiceRate
{
Period = new NpgsqlTypes.NpgsqlRange<DateTime>(
new DateTime(2021, 06, 01),
true,
false,
default,
false,
true),
});
This maps to (note the time part):
Executing DbCommand [Parameters=[@p0='[01.06.2021 0:00:00,)' (DbType = Object)], CommandType='Text', CommandTimeout='30']
INSERT INTO "ServiceRates" ("Period")
VALUES (@p0)
RETURNING "Id";
And as a result:
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
---> Npgsql.PostgresException (0x80004005): 42804: column "Period" is of type daterange but expression is of type tstzrange
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 to tsrange
in other entities.
BTW, docs mention that this should be mapped to daterange
already.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Date Range Picker (JavaScript Component for Bootstrap) ...
Currently I have been working with code which I am not the author and the user spotted a very specific problem I couldn't...
Read more >NpgsqlRange<DateTime>.Contains not working when ...
I explicitly map to daterange as it is saved as daterange in the database. Would using NodaTime solve this problem? Or..
Read more >Is it possible to use a date range as map's key and then ...
The problem here is that the keys are ranges and I want to fetch based on a date that lies between the ranges....
Read more >Date Range URLParams Problem - App Building
This can be reproduced by creating a dateRange component, mapping the urlparams as shown in the screenshot, setting a value, and then reloading...
Read more >Date not correctly detected/mapped - Kibana
Hi all, first of all, I must say i am new in this elastic world. I hace a setup with rsyslog-logstash-Kibana (and also...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.@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:Attempted repro