EF Core persistence providers
The Entity Framework Core (EF Core) persistence providers give Elsa a shared way to store workflow and platform data in a relational database. The shared layer connects Elsa storage contracts to database contexts, while SQLite, SQL Server, PostgreSQL, MySQL, and Oracle provide the database-specific setup and migration history. Identity persistence also stores revoked sign-in sessions so an application can invalidate active sessions. See the persistence overview for the wider persistence model, persistence vNext for the newer persistence direction, and secrets, tenants, and identity for the wider identity model.
System role
Persistence boundary
The EF Core layer turns Elsa persistence services into database-backed stores. Each store uses a context for one data area, so workflow management data can be kept separate from runtime, tenant, identity, label, and alteration data while all areas share the same tenant and migration rules. The common context base is defined in src/…/ElsaDbContextBase.cs.
The main flow moves from an Elsa feature to a provider choice, then to a database context and its stores.
flowchart LR
A[Elsa persistence feature] --> B[Database provider]
B --> C[EF Core context]
C --> D[Entity stores]
D --> E[Workflow and platform data]
C --> F[Provider migrations]
References: src/…/ElsaDbContextBase.cs• L8-52 src/…/PersistenceFeatureBase.cs• L13-67 src/…/EntityStore.cs• L6-19
Data responsibilities
The providers cover the core data needed to define, run, and manage Elsa workflows. Each responsibility maps to an Elsa feature and has its own EF Core context and store registrations.
| Responsibility | Data held | Elsa capability connected |
|---|---|---|
| Workflow management | Workflow definitions and workflow instances | Definition lookup, versioning, instance state, summaries, and deletion |
| Workflow runtime | Triggers, bookmarks, bookmark queues, dead-letter items, execution logs, activity logs, and key-value pairs | Workflow wake-up, execution history, and runtime state |
| Tenant management | Tenant records | Tenant lookup and tenant administration |
| Identity | Users, applications, roles, and revoked sign-in sessions | User, application, and role storage plus session invalidation. User and role names are unique within a tenant. Application names and client IDs are also unique within a tenant. |
| Labels | Labels and workflow-definition label links | Workflow classification and label queries |
| Alterations | Alteration plans and jobs | Planned changes to workflow data |
The management context stores workflow definitions and instances. The runtime context stores the records that let the runtime find work and record what happened. The identity context stores users, applications, roles, and revoked sessions. Its user, application, and role names follow tenant-aware uniqueness rules, as shown in src/…/DbContext.cs, src/…/DbContext.cs, src/…/DbContext.cs, and src/…/Configurations.cs.
References: src/…/DbContext.cs• L8-38 src/…/DbContext.cs• L7-75 src/…/DbContext.cs• L8-29 src/…/DbContext.cs• L6-45 src/…/Configurations.cs• L19-49 src/…/DbContext.cs• L6-23 src/…/DbContext.cs• L9-40
Registration model
Programmatic registration
Programmatic registration starts with an EF Core persistence feature for the required Elsa capability. For identity, UseEntityFrameworkCore connects the identity contracts to the EF Core user, application, role, and revoked-session stores. A database provider extension such as UseSqlite, UseSqlServer, UsePostgreSql, UseMySql, or UseOracle supplies the connection string and provider settings. The feature then registers the matching context factory and store implementations with dependency injection.
The provider call is the boundary between shared Elsa behavior and database-specific behavior. It also selects the provider's migration assembly, so schema changes come from the same provider package that configures the database.
References: src/…/IdentityFeatureExtensions.cs• L8-17 src/…/Feature.cs• L10-37 src/…/SqliteProvidersExtensions.cs• L20-74 src/…/SqlServerProvidersExtensions.cs• L15-57 src/…/PostgreSqlProvidersExtensions.cs• L20-61 src/…/MySqlProvidersExtensions.cs• L20-64 src/…/OracleProvidersExtensions.cs• L21-65
Shell registration
Shell registration exposes the same choices through configuration-driven features. Each provider has combined workflow persistence plus separate features for workflow definitions, workflow instances, and runtime data. The combined feature lets one connection and one set of shared options serve those dependent features.
Provider shell features also exist for the other data responsibilities. Identity uses a provider-specific shell feature because EFCoreIdentityPersistenceShellFeatureBase is only a shared base and is not a standalone shell feature. This lets an application enable only the stores it needs, or use one provider setup for all selected Elsa data areas. The combined workflow feature names follow this pattern:
SqliteWorkflowPersistenceSqlServerWorkflowPersistencePostgreSqlWorkflowPersistenceMySqlWorkflowPersistenceOracleWorkflowPersistence
References: src/…/CombinedPersistenceShellFeatureBase.cs• L7-104 src/…/PersistenceShellFeatureBase.cs• L13-103 src/…/SharedPersistenceSettings.cs• L6-36 src/…/ShellFeature.cs• L8-24
Shared settings
Combined shell features publish shared persistence settings for their dependent features. A dependent feature uses its own setting first and falls back to the shared connection, context options, pooling choice, migration choice, and context-factory lifetime when that setting is not present.
This model supports one database for the workflow areas without forcing the areas to share one context. It also allows an application to override one area when that area needs a different database or setting.
References: src/…/CombinedPersistenceShellFeatureBase.cs• L7-104 src/…/PersistenceShellFeatureBase.cs• L13-103 src/…/SharedPersistenceSettings.cs• L6-36
Database providers
Provider parity
All five providers expose the same high-level persistence responsibilities and the same provider selection shape. Their packages carry the EF Core database driver and the migrations for the Elsa contexts.
| Provider | Provider extension | Main package role |
|---|---|---|
| SQLite | UseSqlite | Local or file-backed relational storage |
| SQL Server | UseSqlServer | SQL Server relational storage |
| PostgreSQL | UsePostgreSql | PostgreSQL relational storage |
| MySQL | UseMySql | MySQL relational storage |
| Oracle | UseOracle | Oracle relational storage |
The common feature layer keeps the store contracts and data responsibilities stable. The provider packages adapt context options, model types, migration history, and schema behavior to the selected database.
References: src/…/Elsa.Persistence.EFCore.Sqlite.csproj• L5-19 src/…/Elsa.Persistence.EFCore.SqlServer.csproj• L5-17 src/…/Elsa.Persistence.EFCore.PostgreSql.csproj• L5-17 src/…/Elsa.Persistence.EFCore.MySql.csproj• L3-18 src/…/Elsa.Persistence.EFCore.Oracle.csproj• L5-17
Provider-specific behavior
The provider packages preserve the shared contracts but add small model rules where database behavior differs. These rules matter when a schema uses JSON, date and time values, or database schemas.
| Provider | Database-specific behavior |
|---|---|
| SQLite | Stores DateTimeOffset values through a string conversion because SQLite has limited support for this type in EF Core queries. |
| SQL Server | Enables the workflow commit transaction when the runtime provider is selected. |
| PostgreSQL | Maps workflow definition string data to the PostgreSQL jsonb type. |
| MySQL | Maps workflow definition string data to JSON and treats Elsa schemas as ignored because MySQL does not use them in the same way. |
| Oracle | Adds provider model mappings for the management and runtime contexts before configuring the Oracle provider. |
These rules are part of provider compatibility rather than separate product behavior. A change to an Elsa entity or to a provider's type support can therefore require matching model and migration changes.
References: src/…/SetupForSqlite.cs• L7-29 src/…/SqlServerProvidersExtensions.cs• L46-57 src/…/SetupForPostgreSql.cs• L8-27 src/…/SetupForMySql.cs• L7-26 src/…/OracleProvidersExtensions.cs• L63-86 src/…/DbContextOptionsBuilder.cs• L17-38
Storage lifecycle
Context and tenant scope
The shared context base applies the selected Elsa schema and model configuration before EF Core builds a model. When multitenancy is enabled, entity data receives the current tenant ID on save and queries apply a tenant filter. Tenant-agnostic records remain visible across tenant scopes.
The context factory carries the current tenant into each created context. This keeps direct store calls and bulk operations aligned with the tenant that owns the current request or operation.
References: src/…/ElsaDbContextBase.cs• L21-78 src/…/TenantAwareDbContextFactory.cs• L8-36 src/…/ApplyTenantId.cs• L9-33 src/…/SetTenantIdFilter.cs• L11-59
Data transformation
Stores translate rich workflow state into database fields when they save it and rebuild that state when they load it. Workflow definitions use serialized state, while workflow instances use serialized and optionally compressed state. Runtime log records keep their payload in serialized form so the database model remains stable while the runtime object can carry structured data.
This boundary means persistence consumers work with workflow objects rather than provider-specific columns. It also means serializer, compression, and model changes can affect existing data even when the store contract does not change.
References: src/…/WorkflowDefinitionStore.cs• L120-199 src/…/WorkflowInstanceStore.cs• L196-257 src/…/WorkflowExecutionLogStore.cs• L14-103
Session revocation
The identity store keeps a revoked session until its expiry time so later authentication checks can reject that session. A revoke request adds the session when it is new or extends the stored expiry when the session is already revoked. The store uses the database as the concurrency boundary, so a concurrent request cannot replace a later expiry with an earlier one.
Expired revocations are removed during revoke operations. The expiry index supports this cleanup, while existence checks give the identity layer a direct answer about whether a session remains revoked.
References: src/…/RevokedSessionStore.cs• L10-58 src/…/Configurations.cs• L44-49 src/…/DbContext.cs• L31-44
Migration lifecycle
Each context has provider-specific migrations and a migration history table. By default, the persistence feature adds a startup task that applies pending migrations. Applications can turn this behavior off per context when another deployment process owns schema changes.
The migration assembly and history table can be changed through ElsaDbContextOptions. The selected provider must still have migrations that match the context model and the target database.
The current identity migration set changes user, role, and application uniqueness from global indexes to tenant-scoped indexes. All five providers carry this identity schema change in their own migration history, so applications can use the same tenant rule with SQLite, SQL Server, PostgreSQL, MySQL, or Oracle.
References: src/…/RunMigrationsStartupTask.cs• L10-28 src/…/RunMigrationsHostedService.cs• L7-32 src/…/ElsaDbContextOptions.cs• L6-41 src/…/ElsaDbContextOptionsExtensions.cs• L18-27 src/…/Configurations.cs• L19-42 src/…/20260823231406_PerTenantIdentityUniqueness.cs• L11-59 src/…/20260823231421_PerTenantIdentityUniqueness.cs• L11-63 src/…/20260823231437_PerTenantIdentityUniqueness.cs• L11-59 src/…/20260823231449_PerTenantIdentityUniqueness.cs• L11-59 src/…/20260823231459_PerTenantIdentityUniqueness.cs• L11-63 src/…/RuntimeElsaDbContextModelSnapshot.cs• L1-20
Change checklist
When these files or sections are changed, remember to consider these:
- When an entity or serialized state field changes, check the shared context model, every provider migration set, and any provider-specific type mapping.
- When identity uniqueness rules change, update the shared identity model and the identity migration and model snapshot for each provider.
- When identity session revocation changes, keep the identity context, revoked-session store, expiry index, and provider migration sets aligned.
- When a new store responsibility is added, connect its store to both the programmatic feature and the matching provider shell feature before expecting the data to persist.
- When a provider name or combined shell feature changes, keep its shared-settings key, dependent feature list, package manifest metadata, and migration assembly aligned.
- When tenant behavior changes, review both query filtering and save-time tenant assignment because bulk writes do not rely on normal EF Core query filters.
- When migration ownership changes, align the per-context
RunMigrationssetting with the deployment process so startup does not race with an external schema update.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A persistence feature has no connection string and no shared shell setting | Context creation fails before a store can read or write data | Configure the feature directly or configure its combined persistence feature. |
| A provider migration set does not match the selected context model | Startup migration fails or the database schema cannot support the store | Keep entity changes, provider mappings, and all five relevant migration sets in sync. |
| An identity migration keeps global unique indexes after the model becomes tenant-scoped | Two tenants cannot use the same user, role, or application name as intended | Check the identity migration and provider model snapshot for tenant-based unique indexes. |
| A revoked session is inserted without handling a concurrent duplicate | A later expiry can be replaced by an earlier one or a revoke request can fail under a race | Preserve the conditional extend-then-add behavior and classify duplicate-key results as a retry. |
| Expired revoked sessions are not removed | The identity store keeps stale revocation rows and its data grows over time | Retain expiry indexing and the cleanup performed during session revocation. |
| Multitenancy is enabled but a bulk write bypasses tenant assignment | Records can be written without the current tenant or can cross tenant boundaries | Preserve the save handler and explicit tenant handling used for bulk upserts. |
SQLite receives a query that depends on native DateTimeOffset support | Date and time queries can fail or behave differently from other providers | Keep the SQLite date and time conversion in the provider model setup. |
| A runtime provider does not enable the required workflow commit transaction | Related runtime writes can commit separately when one operation should be atomic | Check the provider's runtime registration before relying on workflow commit atomicity. |
Key files
| File | Why to read it |
|---|---|
| src/…/PersistenceFeatureBase.cs | Shows the shared programmatic registration boundary for contexts, stores, tenant handlers, and migrations. |
| src/…/PersistenceShellFeatureBase.cs | Shows how configuration-driven provider features resolve settings and configure a context. |
| src/…/CombinedPersistenceShellFeatureBase.cs | Shows how one workflow persistence setting is shared by dependent features. |
| src/…/ElsaDbContextBase.cs | Shows the common schema, tenant, model, and save behavior for all contexts. |
| src/…/DbContext.cs | Defines the workflow definition and instance data boundary. |
| src/…/DbContext.cs | Defines the workflow runtime data boundary. |
| src/…/Configurations.cs | Defines the tenant-scoped identity uniqueness rules and revoked-session expiry index shared by all EF Core providers. |
| src/…/DbContext.cs | Defines the identity data boundary for users, applications, roles, and revoked sessions. |
| src/…/RevokedSessionStore.cs | Shows how session revocation survives concurrent requests and removes expired records. |
| src/…/Feature.cs | Connects identity contracts to the EF Core stores during programmatic registration. |
| src/…/ShellFeature.cs | Defines the shared identity shell registration used by provider-specific features. |
| src/…/WorkflowRuntimePersistenceFeature.cs | Connects runtime contracts to EF Core stores and optional commit transactions. |
| src/…/SqliteProvidersExtensions.cs | Illustrates provider selection and SQLite-specific model handler registration. |
| src/…/SqlServerProvidersExtensions.cs | Illustrates SQL Server selection and runtime transaction behavior. |
| src/…/PostgreSqlProvidersExtensions.cs | Illustrates PostgreSQL selection and model handler registration. |
| src/…/MySqlProvidersExtensions.cs | Illustrates MySQL selection and model handler registration. |
| src/…/OracleProvidersExtensions.cs | Illustrates Oracle selection and provider model configuration. |