愿你出走半生,归来仍是少年!
由于.NET6.0的变更,Npgsql 6.0对时间戳的映射方式进行了一些重要的更改。 Date and Time Handling | Npgsql Documentation https://www.npgsql.org/doc/types/datetime.html
现遇见问题如下:?
Cannot write DateTime with Kind=Local 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.
解决方式:
?????????在调用PG之前的初始化地方(Startup.Class 或 Program.cs)添如下设置:
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch注解如下:
AppContext.SetSwitch(String, Boolean) 方法 (System) | Microsoft Docs设置开关的值。 https://docs.microsoft.com/zh-cn/dotnet/api/system.appcontext.setswitch?view=net-6.0
|