diff --git a/src/modules/Elsa.Persistence.EntityFrameworkCore/Modules/Runtime/WorkflowStateStore.cs b/src/modules/Elsa.Persistence.EntityFrameworkCore/Modules/Runtime/WorkflowStateStore.cs index d45a2ab02..d852fe4a7 100644 --- a/src/modules/Elsa.Persistence.EntityFrameworkCore/Modules/Runtime/WorkflowStateStore.cs +++ b/src/modules/Elsa.Persistence.EntityFrameworkCore/Modules/Runtime/WorkflowStateStore.cs @@ -18,9 +18,9 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore private readonly IDbContextFactory _dbContextFactory; public EFCoreWorkflowStateStore( - IDbContextFactory dbContextFactory, - Store store, - SerializerOptionsProvider serializerOptionsProvider, + IDbContextFactory dbContextFactory, + Store store, + SerializerOptionsProvider serializerOptionsProvider, ISystemClock systemClock) { _serializerOptionsProvider = serializerOptionsProvider; @@ -35,9 +35,8 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore var json = JsonSerializer.Serialize(state, options); var now = _systemClock.UtcNow; var entry = dbContext.Entry(state); - var record = await dbContext.WorkflowStates.FirstOrDefaultAsync(x => x.Id == state.Id, cancellationToken); - if (record == null) + if (entry.Property("CreatedAt").CurrentValue == DateTimeOffset.MinValue) entry.Property("CreatedAt").CurrentValue = now; entry.Property("Data").CurrentValue = json; @@ -55,10 +54,10 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore if (entity == null) return null; - + var entry = dbContext.Entry(entity); var json = entry.Property("Data").CurrentValue; - + // For reading string:object dictionaries where the objects would otherwise be read as JsonElement values. options.Converters.Add(new SystemObjectPrimitiveConverter()); return JsonSerializer.Deserialize(json, options);