Replies: 4 comments 1 reply
-
Yes, You can implement value converter, which allows to define separate conversions for both directions and assign it to all columns you need to alter. See example here |
Beta Was this translation helpful? Give feedback.
-
Thanks, @MaceWindu ! I will check this soon on my side with utc<-->local time conversion. |
Beta Was this translation helpful? Give feedback.
-
Thanks, i will check this IMetadataReader too. |
Beta Was this translation helpful? Give feedback.
-
Hi, It seems Npgsql and linq2db sets the Kind property of DateTime objects automatically to Utc on loading, when column type in the table is timestamptz. Best regards, |
Beta Was this translation helpful? Give feedback.
-
Hi community members,
We are developing a a web application, which is hosted in the cloud using latest Linq2Db, PostgreSql 15, ASP.NET Razor Pages and Blazor.
We would like to store DateTime values in the database in UTC, but in the application on the UI we would like to show and edit in local time. Yes, In the future this app must work in different time zones.
2 years ago in an EF Core 5 project we solved this task with ValueConverter like this:
ValueConverter<DateTime, DateTime> dateTimeConverter = new( v => v.ToUniversalTime(), v => DateTime.SpecifyKind(v, DateTimeKind.Utc).ToLocalTime() );
Here we were able to explicitly specify the conversion in both 2 directions (toProvider / fromProvider).
In this way in business logic and on UI we did not needed to convert between utc and local datetime values anywhere, EF core handled this conversion automatically when reading from or writing to the database.
Please give us some advice to achive the same result! Is it possible to solve this in an elegant way, like that above?
We have found MappingSchema.SetConverter, but it works differently. We don't know where and how to define the conversion between the 2 directions described above.
Thanks, best regards,
Csaba
Beta Was this translation helpful? Give feedback.
All reactions