From 86f396666d2a1c49a2d27ac06d0d966331663d92 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 19 Jan 2022 16:25:56 +0800 Subject: [PATCH 1/2] `EnableLegacyTimestampBehavior` in `AbpEntityFrameworkCorePostgreSqlModule` Resolve #11357 --- .../PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs index 8fffb8359c..596149722d 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using System; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.EntityFrameworkCore.DistributedEvents; using Volo.Abp.Guids; using Volo.Abp.Modularity; @@ -10,6 +11,12 @@ namespace Volo.Abp.EntityFrameworkCore.PostgreSql; )] public class AbpEntityFrameworkCorePostgreSqlModule : AbpModule { + public override void PreConfigureServices(ServiceConfigurationContext context) + { + // https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + } + public override void ConfigureServices(ServiceConfigurationContext context) { Configure(options => From c8eb8416f53874e499829408504fe201c990ca01 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 19 Jan 2022 16:32:26 +0800 Subject: [PATCH 2/2] Remove `EnableLegacyTimestampBehavior`. --- .../PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs | 9 +-------- .../Volo/Abp/EntityFrameworkCore/AbpDbContext.cs | 6 ------ 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs index 596149722d..8fffb8359c 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore.PostgreSql/Volo/Abp/EntityFrameworkCore/PostgreSql/AbpEntityFrameworkCorePostgreSqlModule.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.EntityFrameworkCore.DistributedEvents; using Volo.Abp.Guids; using Volo.Abp.Modularity; @@ -11,12 +10,6 @@ namespace Volo.Abp.EntityFrameworkCore.PostgreSql; )] public class AbpEntityFrameworkCorePostgreSqlModule : AbpModule { - public override void PreConfigureServices(ServiceConfigurationContext context) - { - // https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic - AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); - } - public override void ConfigureServices(ServiceConfigurationContext context) { Configure(options => diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index 8d519784dc..1f55bce770 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -122,12 +122,6 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, if (provider != null) { modelBuilder.SetDatabaseProvider(provider.Value); - - if (provider.Value == EfCoreDatabaseProvider.PostgreSql) - { - // https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic - AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); - } } }