访问PostgreSQL时遇到日期时间类型问题

up9lanfz  于 5个月前  发布在  PostgreSQL
关注(0)|答案(1)|浏览(76)

当我使用ABP引用AuthServer模块时,我注入了AbpIdentityEntityFrameworkCoreModule,并遇到了一个错误An exception occurred while iterating over the results of a query for context type 'Volo' when initializing data Abb Identity IdentityFrameworkCore Identity DbContext '
System InvalidCastException:超出DateTime范围(year必须介于1和9999之间)->System ArgumentOutOfRangeException:刻度必须介于DateTime MinValue刻度和DateTime MaxValue刻度之间(参数“tickets”)在系统日期时间ThrowTicksOutOfRange()在NpgSQL内部类型处理程序DateTimeHandlers DateTimeUtils ReadDateTime(NpgsqlReadBuffer buffer,DateTimeKind kind)-内部异常堆栈跟踪结束-在NpgSQL内部TypeHandlers DateTimeHandlers DateTimeUtils ReadDateTime(NpgsqlReadBuffer buffer,DateTimeKind kind)At NpgSQL Internal TypeHandlers DateTimeHandlers TimestampTzeroRead(NpgsqlReadBuffer buffer,Int32 len,FieldDescription fieldDescription)At NpgSQL NpgsqlDataReader GetFieldValue [T](Int32 ordinal)At lambda_ Met.
我重写了AuthServerModule中的configureServices方法,并添加了

AppContext SetSwitch ("NpgSQL. Enabling LegacyTimestampBehavior", true);
AppContext SetSwitch ("NpgSQL. DisableDateTimeInfinityConversions", true);

字符串
但仍报告上述错误

vof42yt1

vof42yt11#

在你的BulletyFramework项目中,你应该更新两个地方:
1-)* MyProjectFrameworkCore/MyProjectNameDbContextFactory.cs(在MyProjectDbContext方法中添加行)*:

public MyProjectNameDbContext CreateDbContext(string[] args)
{
        //add the below line
        AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
        
        //...
}

字符串
2-)* tyFrameworkCore/MyProjectNametyFrameworkCoreModule.cs(在PreConfigureServices方法中添加该行)*:

public override void PreConfigureServices(ServiceConfigurationContext context)
{
        //add the below line
        AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

        //...
}


查看PR了解更多信息-> https://github.com/abpframework/abp/pull/11871

相关问题