From 741ea2acdfdb5175279f695ea22333e38c783043 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 14 Feb 2025 10:21:28 +0800 Subject: [PATCH] fix: Fixed elsa2 version EF9 compatibility --- .../PersistenceStartupBase.cs | 12 ++++- .../FixedEntityFrameworkBookmarkStore.cs | 50 ++++++++++++++++++ .../FixedEntityFrameworkTriggerStore.cs | 50 ++++++++++++++++++ ...edEntityFrameworkWebhookDefinitionStore.cs | 52 +++++++++++++++++++ ...dEntityFrameworkWorkflowDefinitionStore.cs | 52 +++++++++++++++++++ ...rameworkWorkflowExecutionLogRecordStore.cs | 50 ++++++++++++++++++ ...xedEntityFrameworkWorkflowInstanceStore.cs | 52 +++++++++++++++++++ ...xedEntityFrameworkWorkflowSettingsStore.cs | 52 +++++++++++++++++++ .../WebhooksStartupBase.cs | 5 ++ .../WorkflowSettingsStartupBase.cs | 4 ++ 10 files changed, 378 insertions(+), 1 deletion(-) create mode 100644 aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkBookmarkStore.cs create mode 100644 aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkTriggerStore.cs create mode 100644 aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWebhookDefinitionStore.cs create mode 100644 aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowDefinitionStore.cs create mode 100644 aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowExecutionLogRecordStore.cs create mode 100644 aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowInstanceStore.cs create mode 100644 aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowSettingsStore.cs diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/PersistenceStartupBase.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/PersistenceStartupBase.cs index 1a98e3dde..55ab2f5df 100644 --- a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/PersistenceStartupBase.cs +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/PersistenceStartupBase.cs @@ -1,8 +1,12 @@ -using Elsa.Options; +using DotLiquid; +using Elsa.Options; using Elsa.Persistence.EntityFramework.Core; using Elsa.Persistence.EntityFramework.Core.Extensions; +using Elsa.Persistence.EntityFramework.Core.Stores; +using LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using System; namespace LINGYUN.Abp.Elsa.EntityFrameworkCore; @@ -33,5 +37,11 @@ public abstract class PersistenceStartupBase : EntityFrameworkCoreStartupBase { Configure(options, connectionString); }, autoRunMigrations: false); + + elsa.Services.Replace(ServiceLifetime.Scoped); + elsa.Services.Replace(ServiceLifetime.Scoped); + elsa.Services.Replace(ServiceLifetime.Scoped); + elsa.Services.Replace(ServiceLifetime.Scoped); + elsa.Services.Replace(ServiceLifetime.Scoped); } } diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkBookmarkStore.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkBookmarkStore.cs new file mode 100644 index 000000000..9600d8257 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkBookmarkStore.cs @@ -0,0 +1,50 @@ +using AutoMapper; +using Elsa.Models; +using Elsa.Persistence.EntityFramework.Core.Services; +using Elsa.Persistence.EntityFramework.Core.Stores; +using Elsa.Persistence.Specifications; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; +public class FixedEntityFrameworkBookmarkStore : EntityFrameworkBookmarkStore +{ + public FixedEntityFrameworkBookmarkStore( + IElsaContextFactory dbContextFactory, + IMapper mapper, + ILogger logger) + : base(dbContextFactory, mapper, logger) + { + } + + public async override Task DeleteManyAsync(ISpecification specification, CancellationToken cancellationToken = default) + { + var filter = MapSpecification(specification); + return await DoWork(async dbContext => + { +#if NET7_0_OR_GREATER + return await dbContext.Set().Where(filter).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); +#else + var tuple = dbContext.Set().Where(filter).Select(x => x.Id).ToParametrizedSql(); + var entityLetter = dbContext.Set().EntityType.GetTableName()!.ToLowerInvariant()[0]; + var helper = dbContext.GetService(); + var whereClause = tuple.Item1 + .Substring(tuple.Item1.IndexOf("WHERE", StringComparison.OrdinalIgnoreCase)) + .Replace($"{helper.DelimitIdentifier(entityLetter.ToString())}.", string.Empty); + + for (var i = 0; i < tuple.Item2.Count(); i++) + { + var sqlParameter = tuple.Item2.ElementAt(i); + whereClause = whereClause.Replace(sqlParameter.ParameterName, "{" +$"{i}" + "}"); + } + + var parameters = tuple.Item2.Select(x => x.Value).ToArray(); + return await dbContext.Database.ExecuteSqlRawAsync($"DELETE FROM {dbContext.Set().EntityType.GetSchemaQualifiedTableNameWithQuotes(helper)} {whereClause}", parameters, cancellationToken); +#endif + }, cancellationToken); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkTriggerStore.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkTriggerStore.cs new file mode 100644 index 000000000..37e8174cd --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkTriggerStore.cs @@ -0,0 +1,50 @@ +using AutoMapper; +using Elsa.Models; +using Elsa.Persistence.EntityFramework.Core.Services; +using Elsa.Persistence.EntityFramework.Core.Stores; +using Elsa.Persistence.Specifications; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; +public class FixedEntityFrameworkTriggerStore : EntityFrameworkTriggerStore +{ + public FixedEntityFrameworkTriggerStore( + IElsaContextFactory dbContextFactory, + IMapper mapper, + ILogger logger) + : base(dbContextFactory, mapper, logger) + { + } + + public async override Task DeleteManyAsync(ISpecification specification, CancellationToken cancellationToken = default) + { + var filter = MapSpecification(specification); + return await DoWork(async dbContext => + { +#if NET7_0_OR_GREATER + return await dbContext.Set().Where(filter).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); +#else + var tuple = dbContext.Set().Where(filter).Select(x => x.Id).ToParametrizedSql(); + var entityLetter = dbContext.Set().EntityType.GetTableName()!.ToLowerInvariant()[0]; + var helper = dbContext.GetService(); + var whereClause = tuple.Item1 + .Substring(tuple.Item1.IndexOf("WHERE", StringComparison.OrdinalIgnoreCase)) + .Replace($"{helper.DelimitIdentifier(entityLetter.ToString())}.", string.Empty); + + for (var i = 0; i < tuple.Item2.Count(); i++) + { + var sqlParameter = tuple.Item2.ElementAt(i); + whereClause = whereClause.Replace(sqlParameter.ParameterName, "{" +$"{i}" + "}"); + } + + var parameters = tuple.Item2.Select(x => x.Value).ToArray(); + return await dbContext.Database.ExecuteSqlRawAsync($"DELETE FROM {dbContext.Set().EntityType.GetSchemaQualifiedTableNameWithQuotes(helper)} {whereClause}", parameters, cancellationToken); +#endif + }, cancellationToken); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWebhookDefinitionStore.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWebhookDefinitionStore.cs new file mode 100644 index 000000000..28d71b993 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWebhookDefinitionStore.cs @@ -0,0 +1,52 @@ +using AutoMapper; +using Elsa.Persistence.Specifications; +using Elsa.Serialization; +using Elsa.Webhooks.Models; +using Elsa.Webhooks.Persistence.EntityFramework.Core.Services; +using Elsa.Webhooks.Persistence.EntityFramework.Core.Stores; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; +public class FixedEntityFrameworkWebhookDefinitionStore : EntityFrameworkWebhookDefinitionStore +{ + public FixedEntityFrameworkWebhookDefinitionStore( + IWebhookContextFactory dbContextFactory, + IMapper mapper, + IContentSerializer contentSerializer, + ILogger logger) + : base(dbContextFactory, mapper, contentSerializer, logger) + { + } + + public async override Task DeleteManyAsync(ISpecification specification, CancellationToken cancellationToken = default) + { + var filter = MapSpecification(specification); + return await DoWork(async dbContext => + { +#if NET7_0_OR_GREATER + return await dbContext.Set().Where(filter).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); +#else + var tuple = dbContext.Set().Where(filter).Select(x => x.Id).ToParametrizedSql(); + var entityLetter = dbContext.Set().EntityType.GetTableName()!.ToLowerInvariant()[0]; + var helper = dbContext.GetService(); + var whereClause = tuple.Item1 + .Substring(tuple.Item1.IndexOf("WHERE", StringComparison.OrdinalIgnoreCase)) + .Replace($"{helper.DelimitIdentifier(entityLetter.ToString())}.", string.Empty); + + for (var i = 0; i < tuple.Item2.Count(); i++) + { + var sqlParameter = tuple.Item2.ElementAt(i); + whereClause = whereClause.Replace(sqlParameter.ParameterName, "{" +$"{i}" + "}"); + } + + var parameters = tuple.Item2.Select(x => x.Value).ToArray(); + return await dbContext.Database.ExecuteSqlRawAsync($"DELETE FROM {dbContext.Set().EntityType.GetSchemaQualifiedTableNameWithQuotes(helper)} {whereClause}", parameters, cancellationToken); +#endif + }, cancellationToken); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowDefinitionStore.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowDefinitionStore.cs new file mode 100644 index 000000000..7dc3fdfc5 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowDefinitionStore.cs @@ -0,0 +1,52 @@ +using AutoMapper; +using Elsa.Models; +using Elsa.Persistence.EntityFramework.Core.Services; +using Elsa.Persistence.EntityFramework.Core.Stores; +using Elsa.Persistence.Specifications; +using Elsa.Serialization; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; +public class FixedEntityFrameworkWorkflowDefinitionStore : EntityFrameworkWorkflowDefinitionStore +{ + public FixedEntityFrameworkWorkflowDefinitionStore( + IElsaContextFactory dbContextFactory, + IMapper mapper, + IContentSerializer contentSerializer, + ILogger logger) + : base(dbContextFactory, mapper, contentSerializer, logger) + { + } + + public async override Task DeleteManyAsync(ISpecification specification, CancellationToken cancellationToken = default) + { + var filter = MapSpecification(specification); + return await DoWork(async dbContext => + { +#if NET7_0_OR_GREATER + return await dbContext.Set().Where(filter).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); +#else + var tuple = dbContext.Set().Where(filter).Select(x => x.Id).ToParametrizedSql(); + var entityLetter = dbContext.Set().EntityType.GetTableName()!.ToLowerInvariant()[0]; + var helper = dbContext.GetService(); + var whereClause = tuple.Item1 + .Substring(tuple.Item1.IndexOf("WHERE", StringComparison.OrdinalIgnoreCase)) + .Replace($"{helper.DelimitIdentifier(entityLetter.ToString())}.", string.Empty); + + for (var i = 0; i < tuple.Item2.Count(); i++) + { + var sqlParameter = tuple.Item2.ElementAt(i); + whereClause = whereClause.Replace(sqlParameter.ParameterName, "{" +$"{i}" + "}"); + } + + var parameters = tuple.Item2.Select(x => x.Value).ToArray(); + return await dbContext.Database.ExecuteSqlRawAsync($"DELETE FROM {dbContext.Set().EntityType.GetSchemaQualifiedTableNameWithQuotes(helper)} {whereClause}", parameters, cancellationToken); +#endif + }, cancellationToken); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowExecutionLogRecordStore.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowExecutionLogRecordStore.cs new file mode 100644 index 000000000..d8b46358a --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowExecutionLogRecordStore.cs @@ -0,0 +1,50 @@ +using AutoMapper; +using Elsa.Models; +using Elsa.Persistence.EntityFramework.Core.Services; +using Elsa.Persistence.EntityFramework.Core.Stores; +using Elsa.Persistence.Specifications; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; +public class FixedEntityFrameworkWorkflowExecutionLogRecordStore : EntityFrameworkWorkflowExecutionLogRecordStore +{ + public FixedEntityFrameworkWorkflowExecutionLogRecordStore( + IElsaContextFactory dbContextFactory, + IMapper mapper, + ILogger logger) + : base(dbContextFactory, mapper, logger) + { + } + + public async override Task DeleteManyAsync(ISpecification specification, CancellationToken cancellationToken = default) + { + var filter = MapSpecification(specification); + return await DoWork(async dbContext => + { +#if NET7_0_OR_GREATER + return await dbContext.Set().Where(filter).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); +#else + var tuple = dbContext.Set().Where(filter).Select(x => x.Id).ToParametrizedSql(); + var entityLetter = dbContext.Set().EntityType.GetTableName()!.ToLowerInvariant()[0]; + var helper = dbContext.GetService(); + var whereClause = tuple.Item1 + .Substring(tuple.Item1.IndexOf("WHERE", StringComparison.OrdinalIgnoreCase)) + .Replace($"{helper.DelimitIdentifier(entityLetter.ToString())}.", string.Empty); + + for (var i = 0; i < tuple.Item2.Count(); i++) + { + var sqlParameter = tuple.Item2.ElementAt(i); + whereClause = whereClause.Replace(sqlParameter.ParameterName, "{" +$"{i}" + "}"); + } + + var parameters = tuple.Item2.Select(x => x.Value).ToArray(); + return await dbContext.Database.ExecuteSqlRawAsync($"DELETE FROM {dbContext.Set().EntityType.GetSchemaQualifiedTableNameWithQuotes(helper)} {whereClause}", parameters, cancellationToken); +#endif + }, cancellationToken); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowInstanceStore.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowInstanceStore.cs new file mode 100644 index 000000000..7eb21e3bb --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowInstanceStore.cs @@ -0,0 +1,52 @@ +using AutoMapper; +using Elsa.Models; +using Elsa.Persistence.EntityFramework.Core.Services; +using Elsa.Persistence.EntityFramework.Core.Stores; +using Elsa.Persistence.Specifications; +using Elsa.Serialization; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; +public class FixedEntityFrameworkWorkflowInstanceStore : EntityFrameworkWorkflowInstanceStore +{ + public FixedEntityFrameworkWorkflowInstanceStore( + IElsaContextFactory dbContextFactory, + IMapper mapper, + IContentSerializer contentSerializer, + ILogger logger) + : base(dbContextFactory, mapper, contentSerializer, logger) + { + } + + public async override Task DeleteManyAsync(ISpecification specification, CancellationToken cancellationToken = default) + { + var filter = MapSpecification(specification); + return await DoWork(async dbContext => + { +#if NET7_0_OR_GREATER + return await dbContext.Set().Where(filter).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); +#else + var tuple = dbContext.Set().Where(filter).Select(x => x.Id).ToParametrizedSql(); + var entityLetter = dbContext.Set().EntityType.GetTableName()!.ToLowerInvariant()[0]; + var helper = dbContext.GetService(); + var whereClause = tuple.Item1 + .Substring(tuple.Item1.IndexOf("WHERE", StringComparison.OrdinalIgnoreCase)) + .Replace($"{helper.DelimitIdentifier(entityLetter.ToString())}.", string.Empty); + + for (var i = 0; i < tuple.Item2.Count(); i++) + { + var sqlParameter = tuple.Item2.ElementAt(i); + whereClause = whereClause.Replace(sqlParameter.ParameterName, "{" +$"{i}" + "}"); + } + + var parameters = tuple.Item2.Select(x => x.Value).ToArray(); + return await dbContext.Database.ExecuteSqlRawAsync($"DELETE FROM {dbContext.Set().EntityType.GetSchemaQualifiedTableNameWithQuotes(helper)} {whereClause}", parameters, cancellationToken); +#endif + }, cancellationToken); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowSettingsStore.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowSettingsStore.cs new file mode 100644 index 000000000..ad31ba381 --- /dev/null +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/Stores/FixedEntityFrameworkWorkflowSettingsStore.cs @@ -0,0 +1,52 @@ +using AutoMapper; +using Elsa.Persistence.Specifications; +using Elsa.Serialization; +using Elsa.WorkflowSettings.Models; +using Elsa.WorkflowSettings.Persistence.EntityFramework.Core.Services; +using Elsa.WorkflowSettings.Persistence.EntityFramework.Core.Stores; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; +public class FixedEntityFrameworkWorkflowSettingsStore : EntityFrameworkWorkflowSettingsStore +{ + public FixedEntityFrameworkWorkflowSettingsStore( + IWorkflowSettingsContextFactory dbContextFactory, + IMapper mapper, + IContentSerializer contentSerializer, + ILogger logger) + : base(dbContextFactory, mapper, contentSerializer, logger) + { + } + + public async override Task DeleteManyAsync(ISpecification specification, CancellationToken cancellationToken = default) + { + var filter = MapSpecification(specification); + return await DoWork(async dbContext => + { +#if NET7_0_OR_GREATER + return await dbContext.Set().Where(filter).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); +#else + var tuple = dbContext.Set().Where(filter).Select(x => x.Id).ToParametrizedSql(); + var entityLetter = dbContext.Set().EntityType.GetTableName()!.ToLowerInvariant()[0]; + var helper = dbContext.GetService(); + var whereClause = tuple.Item1 + .Substring(tuple.Item1.IndexOf("WHERE", StringComparison.OrdinalIgnoreCase)) + .Replace($"{helper.DelimitIdentifier(entityLetter.ToString())}.", string.Empty); + + for (var i = 0; i < tuple.Item2.Count(); i++) + { + var sqlParameter = tuple.Item2.ElementAt(i); + whereClause = whereClause.Replace(sqlParameter.ParameterName, "{" +$"{i}" + "}"); + } + + var parameters = tuple.Item2.Select(x => x.Value).ToArray(); + return await dbContext.Database.ExecuteSqlRawAsync($"DELETE FROM {dbContext.Set().EntityType.GetSchemaQualifiedTableNameWithQuotes(helper)} {whereClause}", parameters, cancellationToken); +#endif + }, cancellationToken); + } +} diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/WebhooksStartupBase.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/WebhooksStartupBase.cs index e622616d2..2c040bc2c 100644 --- a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/WebhooksStartupBase.cs +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/WebhooksStartupBase.cs @@ -1,7 +1,10 @@ using Elsa.Activities.Webhooks; using Elsa.Options; +using Elsa.Persistence.EntityFramework.Core.Stores; using Elsa.Webhooks.Persistence.EntityFramework.Core; using Elsa.Webhooks.Persistence.EntityFramework.Core.Extensions; +using Elsa.Webhooks.Persistence.EntityFramework.Core.Stores; +using LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -37,5 +40,7 @@ public abstract class WebhooksStartupBase : EntityFrameworkWebhookStartupBase Configure(options, connectionString); }, autoRunMigrations: false); elsa.Services.AddSingleton(webhookOptionsBuilder.WebhookOptions); + + elsa.Services.Replace(ServiceLifetime.Scoped); } } diff --git a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/WorkflowSettingsStartupBase.cs b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/WorkflowSettingsStartupBase.cs index edb703939..5f90dbde4 100644 --- a/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/WorkflowSettingsStartupBase.cs +++ b/aspnet-core/modules/elsa/LINGYUN.Abp.Elsa.EntityFrameworkCore/LINGYUN/Abp/Elsa/EntityFrameworkCore/WorkflowSettingsStartupBase.cs @@ -3,6 +3,8 @@ using Elsa.WorkflowSettings; using Elsa.WorkflowSettings.Extensions; using Elsa.WorkflowSettings.Persistence.EntityFramework.Core; using Elsa.WorkflowSettings.Persistence.EntityFramework.Core.Extensions; +using Elsa.WorkflowSettings.Persistence.EntityFramework.Core.Stores; +using LINGYUN.Abp.Elsa.EntityFrameworkCore.Stores; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -39,5 +41,7 @@ public abstract class WorkflowSettingsStartupBase : EntityFrameworkWorkflowSetti }, autoRunMigrations: false); elsa.Services.AddScoped((provider) => workflowSettingsOptionsBuilder.WorkflowSettingsOptions.WorkflowSettingsStoreFactory(provider)); elsa.AddWorkflowSettings(); + + elsa.Services.Replace(ServiceLifetime.Scoped); } }