-
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
.NET 6 RC1 and issues with datetime fields #2000
Comments
@viniciusverasdossantos these are intentional breaking changes which are in the process of being documented: see npgsql/doc#116 for the details. The changes here are quite big, and we want to make it as easy as possible for users to transition - it would be good to have any feedback after reading the release and breaking changes notes. |
@viniciusverasdossantos the release notes page is now online here. |
@roji where we can see examples how to migrate from old version to new ? |
@Taifunov have you taken a look at the release notes? I plan to write more docs (and a blog post explaining the context), but hopefully these notes should be enough to start - please let me know how it goes! |
Am closing this issue, but anyone needing assistance is still welcome to post questions here (after reading the release notes). |
@roji I really appreciate the great work. But I'm failing to understand choosing |
@3ldar I understand and I agree that this isn't an ideal situation; FWIW I thought about this a lot and discussed with the other people working on Npgsql. Here's some context (I need to sit down and write a post about this):
To summarize, yeah, assuming you're dealing with UTC timestamps in your code, you must make that explicit by making sure your DateTimes actually have Kind=Utc. My hope is that despite an initial painful upgrade, users end up with a much saner, safer timestamp mapping system. And there's a compatibility flag to allow you to upgrade to 6.0 without going through this change (or deferring it for later). I'd be very interested to hear any other feedback on this! Specifically about migrating existing data:
Can you provide more info on what you mean here? I wrote some migration notes from timestamp to timestamptz, have you tried those? |
@roji I missed below part of the notes :
It was just mentioned in the notes. The previous value was I should have read that more carefully before migrating blindly. And thanks for your kind reply. |
@3ldar sure thing. You should be able to correct the data by executing the down migration (migrating back from timestamptz to timestamp, but ensuring you have the same TimeZone as you had when doing the up migration!). At that point you can edit the migration to add |
@roji appreciate the effort which you have being givine and I am a fan of your work. Having said that this breaking change is something needs more elaboration and explanation. I guess the current "Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0" . Has some kind of bug. After going through the documentation I found that only Utc seems to be working.. i.e. DateTime.UtcNow in only working. DateTime.Now does not work. I made the Columns as "timestamp", "timestamptz" and all other combinations but I only get InvalidCastException: Cannot write DateTime with Kind=Local to PostgreSQL type 'timestamp with time zone', only UTC is supported. Now this has colapsed my whole application; since we are planning to upgrade it to from .Net 5 to .net 6. |
@amitdixit you should be able to write DateTime.Now to |
I'm getting the same error when loading entities from the database although I added |
DbContext constructor may not be the best place to set that switch. You should set this switch at the start-up config your application preferably before you configure services. Also, make sure that you don't have any |
@VILLAN3LL3 can you please open a new issue with a runnable code sample that shows the problem? |
|
I'm not sure what's the proper place to put this, but I had one slight issue with the suggested |
Thanks @hhyyrylainen, I'll update the docs. |
I got the same issue yesterday. @roji When I tried to debug, it looks like the Entity Framework deserializes |
@iam-ben yes, Npgsql 6.0 reads PG If the actual data you're storing in the database is UTC timestamps in your database, consider using |
Thank you @roji for a quick response! Yeah... currently I have plenty of |
This is how I made it working [Column(TypeName = "timestamp without time zone")] |
All of my datatypes are timezone with time stamp in our database. The model type is DateTime. I'm setting a date value to DateTime.UtcNow in an insert, but am getting this error: InvalidCastException: Cannot write DateTime with Kind=UTC to PostgreSQL type 'timestamp without time zone', consider using 'timestamp with time zone'. Note that it's not possible to mix DateTimes with different Kinds in an array/range. See the Npgsql.EnableLegacyTimestampBehavior AppContext switch to enable legacy behavior. I tried setting a ColumnAttribute on the column to Column(TypeName="timestamptz") and am getting this error: |
@ItWorksOnMyMachine, for those who met the similar problem, |
@propell-ant the type name |
@roji, I have checked it again - indeed, both |
Thanks for confirming @propell-ant! |
System.InvalidCastException: 'Cannot write DateTime with Kind=Unspecified to PostgreSQL type 'timestamp with time zone', only UTC is supported. Note that it's not possible to mix DateTimes with different Kinds in an array/range. See the Npgsql.EnableLegacyTimestampBehavior AppContext switch to enable legacy behavior.'
I have updated the packages to .NET 6 RC1 and am having issues with datetime fields.
The text was updated successfully, but these errors were encountered: