diff --git a/src/modules/Elsa.Persistence.EFCore.Common/Store.cs b/src/modules/Elsa.Persistence.EFCore.Common/Store.cs index 680e2ca7a8..c8ddbdd43f 100644 --- a/src/modules/Elsa.Persistence.EFCore.Common/Store.cs +++ b/src/modules/Elsa.Persistence.EFCore.Common/Store.cs @@ -182,7 +182,7 @@ public async Task SaveManyAsync( } // When doing a custom SQL query (Bulk Upsert), none of the installed query filters will be applied. Hence, we are assigning the current tenant ID explicitly. - var tenantId = serviceProvider.GetRequiredService().Tenant?.Id; + var tenantId = serviceProvider.GetRequiredService().TenantId; foreach (var entity in entityList) { if (entity is Entity entityWithTenant) diff --git a/src/modules/Elsa.Persistence.EFCore.Common/TenantAwareDbContextFactory.cs b/src/modules/Elsa.Persistence.EFCore.Common/TenantAwareDbContextFactory.cs index 8128553ce3..bcf4fd2272 100644 --- a/src/modules/Elsa.Persistence.EFCore.Common/TenantAwareDbContextFactory.cs +++ b/src/modules/Elsa.Persistence.EFCore.Common/TenantAwareDbContextFactory.cs @@ -32,6 +32,6 @@ public async Task CreateDbContextAsync(CancellationToken cancellatio private void SetTenantId(TDbContext context) { if (context is ElsaDbContextBase elsaContext) - elsaContext.TenantId = tenantAccessor.Tenant?.Id; + elsaContext.TenantId = tenantAccessor.TenantId; } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Runtime/Providers/ClrWorkflowsProvider.cs b/src/modules/Elsa.Workflows.Runtime/Providers/ClrWorkflowsProvider.cs index debe17fb28..94aa271a2e 100644 --- a/src/modules/Elsa.Workflows.Runtime/Providers/ClrWorkflowsProvider.cs +++ b/src/modules/Elsa.Workflows.Runtime/Providers/ClrWorkflowsProvider.cs @@ -1,3 +1,4 @@ +using Elsa.Common.Multitenancy; using Elsa.Workflows.Management.Materializers; using Elsa.Workflows.Runtime.Features; using Elsa.Workflows.Runtime.Options; @@ -10,7 +11,7 @@ namespace Elsa.Workflows.Runtime.Providers; /// Provides workflows to the system that are registered with /// [UsedImplicitly] -public class ClrWorkflowsProvider( +public class ( IOptions options, IWorkflowBuilderFactory workflowBuilderFactory, IServiceProvider serviceProvider) : IWorkflowsProvider @@ -41,7 +42,7 @@ private async Task BuildWorkflowAsync(Func> PopulateStoreAsync(bool index { var providers = _workflowDefinitionProviders(); var workflowDefinitions = new List(); - var currentTenantId = (_tenantAccessor.Tenant?.Id).NormalizeTenantId(); + var currentTenantId = _tenantAccessor.TenantId; foreach (var provider in providers) { @@ -69,7 +69,7 @@ public async Task> PopulateStoreAsync(bool index foreach (var result in results) { // Normalize tenant IDs for comparison (null becomes empty string) - var definitionTenantId = result.Workflow.Identity.TenantId.NormalizeTenantId(); + var definitionTenantId = result.Workflow.Identity.TenantId ?? _tenantAccessor.TenantId; // Only import workflows belonging to the current tenant or tenant-agnostic workflows (TenantId = "*"). if (definitionTenantId != currentTenantId && definitionTenantId != Tenant.AgnosticTenantId) @@ -191,8 +191,8 @@ private async Task AddOrUpdateCoreAsync(MaterializedWorkflow await UpdateIsPublished(); // Determine the tenant ID for the workflow definition - // If the workflow has no tenant ID, use the current tenant (normalized to handle null -> "") - var workflowTenantId = workflow.Identity.TenantId ?? (_tenantAccessor.Tenant?.Id).NormalizeTenantId(); + // If the workflow has no tenant ID, use the current tenant (normalized to handle null -> "*") + var workflowTenantId = workflow.Identity.TenantId ?? _tenantAccessor.TenantId; var workflowDefinition = existingDefinitionVersion ?? new WorkflowDefinition {