EF Core Setup
Minimal example to enable Entity Framework Core persistence for Elsa Workflows, including database provider setup and migrations.
This document provides a minimal, copy-pasteable example for configuring Elsa Workflows with Entity Framework Core persistence.
Prerequisites
.NET 8.0 or later
Database server (PostgreSQL, SQL Server, SQLite, or MySQL)
Elsa v3.x packages
NuGet Packages
For PostgreSQL:
dotnet add package Elsa
dotnet add package Elsa.EntityFrameworkCore.PostgreSQL
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQLFor SQL Server:
dotnet add package Elsa
dotnet add package Elsa.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.SqlServerFor SQLite:
dotnet add package Elsa
dotnet add package Elsa.EntityFrameworkCore.Sqlite
dotnet add package Microsoft.EntityFrameworkCore.SqliteMinimal Configuration
Program.cs
appsettings.json
PostgreSQL:
SQL Server:
SQLite:
Applying Migrations
Option 1: Automatic Migrations (Development)
Set ef.RunMigrations = true in the configuration above. Migrations will be applied automatically when the application starts.
Warning: Automatic migrations are convenient for development but not recommended for production. Use manual migrations in production environments.
Option 2: CLI Migrations (Production)
1. Install EF Core Tools:
2. Generate Migration Script (for review):
3. Apply Migrations:
Multiple Contexts
Elsa uses separate DbContexts for different concerns:
ManagementElsaDbContext— Workflow definitions and instancesRuntimeElsaDbContext— Bookmarks, inbox, execution logs
Apply migrations for both contexts:
Advanced Configuration
Separate Databases
Use separate databases for management and runtime data:
Connection Pooling
Configure connection pool settings for high-concurrency scenarios:
Retry on Transient Failures
Configure retry logic for transient database errors:
Troubleshooting
Migration Errors
Error: The term 'dotnet-ef' is not recognized
Solution: Install EF Core tools:
Error: No migrations were applied. The database is already up to date.
Solution: This is informational. The database schema is current.
Error: Login failed for user or password authentication failed
Solution: Verify connection string credentials and database permissions.
Logging
Enable EF Core logging to diagnose issues:
Related Documentation
Persistence Guide — Overview and provider comparison
Indexing Notes — Recommended indexes for EF Core
Database Configuration — Basic setup
Last Updated: 2025-11-28
Last updated