dotnetcore / WTM

Use WTM to write .netcore app fast !!!
https://wtmdoc.walkingtec.cn
MIT License
4.24k stars 882 forks source link

关于pgsql 时间戳的问题 #624

Closed DionFlinck closed 1 year ago

DionFlinck commented 1 year ago

pgsql15数据库,导入excel时,报错fail: Microsoft.EntityFrameworkCore.Database.Command[20102] => SpanId:2f2eec8a7e6f7564, TraceId:e24894d9ede27a060be76059583f0d76, ParentId:0000000000000000 => ConnectionId:0HMUDG4JCH0QI => RequestPath:/_Framework/Upload RequestId:0HMUDG4JCH0QI:00000006 => WalkingTec.Mvvm.Mvc._FrameworkController.Upload (WalkingTec.Mvvm.Mvc) Failed executing DbCommand (3ms) [Parameters=[@p0='aa7ac25b-ca23-49c9-83fc-7929cee84bba', @p1=NULL, @p2='0x504B0304140006000800000021004AF525D18401000091060000130008025B43...', @p3='xlsx' (Nullable = false), @p4='C_EXCEPTION_CODETemplateVM_2023-09-28_04^01^03.xlsx' (Nullable = false), @p5=NULL, @p6='13390', @p7=NULL, @p8='database', @p9=NULL, @p10='2023-10-15T21:18:28.0391025+08:00' (DbType = DateTime)], CommandType='Text', CommandTimeout='30'] INSERT INTO "FileAttachments" ("ID", "ExtraInfo", "FileData", "FileExt", "FileName", "HandlerInfo", "Length", "Path", "SaveMode", "TenantCode", "UploadTime") VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10); fail: Microsoft.EntityFrameworkCore.Update[10000] => SpanId:2f2eec8a7e6f7564, TraceId:e24894d9ede27a060be76059583f0d76, ParentId:0000000000000000 => ConnectionId:0HMUDG4JCH0QI => RequestPath:/_Framework/Upload RequestId:0HMUDG4JCH0QI:00000006 => WalkingTec.Mvvm.Mvc._FrameworkController.Upload (WalkingTec.Mvvm.Mvc) An exception occurred in the database while saving changes for context type 'XTOS.DataAccess.DataContext'. Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details. ---> System.InvalidCastException: 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.

按照网上的解决也加入了 public void Configure(IApplicationBuilder app, IOptionsMonitor<Configs> configs) { AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); IconFontsHelper.GenerateIconFont(); 还是不好用。

DionFlinck commented 1 year ago

DataContext加入如下 static DataContext() { AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); }