From 006e0bbbb4afe0b6688474b2ca2ee6cd4ef6ac5e Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 31 Jan 2025 00:52:49 +0100 Subject: [PATCH] Ignore EF Core pending model changes warnings and update Oracle DSN. Added configuration to suppress EF Core PendingModelChangesWarning for better compatibility with newer .NET versions. Updated Oracle connection string to use "localhost" for consistency and clarity in appsettings.json. --- src/apps/Elsa.Server.Web/appsettings.json | 2 +- .../ElsaDbContextBase.cs | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/apps/Elsa.Server.Web/appsettings.json b/src/apps/Elsa.Server.Web/appsettings.json index ae6820a3f..20591e80b 100644 --- a/src/apps/Elsa.Server.Web/appsettings.json +++ b/src/apps/Elsa.Server.Web/appsettings.json @@ -13,7 +13,7 @@ "Sqlite": "Data Source=App_Data/elsa.sqlite.db;Cache=Shared;", "MySql": "Server=localhost;Database=elsa;Uid=admin;Pwd=password;", "PostgreSql": "Server=localhost;Username=elsa;Database=elsa;Port=5432;Password=elsa;SSLMode=Prefer;MaxPoolSize=2000;Timeout=60", - "Oracle": "User Id=SYSTEM;Password=elsa;Data Source=oracle:1521/ORCLPDB1", + "Oracle": "User Id=SYSTEM;Password=elsa;Data Source=localhost:1521/FREE;", "CockroachDb": "Host=localhost;Port=26257;Database=elsa;SslMode=Disable;Username=root;IncludeErrorDetail=true", "MongoDb": "mongodb://localhost:27017/elsa-workflows", "AzureServiceBus": "", diff --git a/src/modules/Elsa.EntityFrameworkCore.Common/ElsaDbContextBase.cs b/src/modules/Elsa.EntityFrameworkCore.Common/ElsaDbContextBase.cs index 2a677bb6f..85407dff4 100644 --- a/src/modules/Elsa.EntityFrameworkCore.Common/ElsaDbContextBase.cs +++ b/src/modules/Elsa.EntityFrameworkCore.Common/ElsaDbContextBase.cs @@ -2,6 +2,7 @@ using Elsa.Common.Entities; using Elsa.Common.Multitenancy; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.DependencyInjection; namespace Elsa.EntityFrameworkCore; @@ -16,7 +17,7 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema EntityState.Added, EntityState.Modified, }; - + protected readonly IServiceProvider ServiceProvider; public string? TenantId { get; set; } @@ -43,14 +44,14 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema // ReSharper disable once VirtualMemberCallInConstructor Schema = !string.IsNullOrWhiteSpace(elsaDbContextOptions?.SchemaName) ? elsaDbContextOptions.SchemaName : ElsaSchema; - + var tenantAccessor = serviceProvider.GetService(); var tenantId = tenantAccessor?.Tenant?.Id; - - if(!string.IsNullOrWhiteSpace(tenantId)) + + if (!string.IsNullOrWhiteSpace(tenantId)) TenantId = tenantId; } - + /// public override async Task SaveChangesAsync(CancellationToken cancellationToken = default) { @@ -58,6 +59,13 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema return await base.SaveChangesAsync(cancellationToken); } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { +#if NET9_0_OR_GREATER + optionsBuilder.ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning)); +#endif + } + /// protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -66,7 +74,7 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema if (!Database.IsSqlite()) modelBuilder.HasDefaultSchema(Schema); } - + var entityTypeHandlers = ServiceProvider.GetServices().ToList(); foreach (var entityType in modelBuilder.Model.GetEntityTypes().ToList()) @@ -77,7 +85,7 @@ public abstract class ElsaDbContextBase : DbContext, IElsaDbContextSchema } } } - + private async Task OnBeforeSavingAsync(CancellationToken cancellationToken) { var handlers = ServiceProvider.GetServices().ToList();