Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;

Expand Down
11 changes: 11 additions & 0 deletions src/persistence/Elsa.Persistence.EFCore.Sqlite/SetupForSqlite.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.Extensions.DependencyInjection;

namespace Elsa.Persistence.EFCore.Sqlite;

Expand All @@ -12,6 +13,7 @@ public class SetupForSqlite : IEntityModelCreatingHandler
/// <inheritdoc />
public void Handle(ElsaDbContextBase dbContext, ModelBuilder modelBuilder, IMutableEntityType entityType)
{
// First check if this is a SQLite database - if not, don't do anything
if(!dbContext.Database.IsSqlite())
return;

Expand All @@ -27,4 +29,13 @@ public void Handle(ElsaDbContextBase dbContext, ModelBuilder modelBuilder, IMuta
.HasConversion(new DateTimeOffsetToStringConverter());
}
}

/// <summary>
/// Registers the handler with the service collection if it's not already registered.
/// </summary>
public static IServiceCollection AddSetupForSqliteHandler(IServiceCollection services)
{
services.AddScoped<IEntityModelCreatingHandler, SetupForSqlite>();
return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public static TFeature UseSqlite<TFeature, TDbContext>(this PersistenceFeatureBa
where TDbContext : ElsaDbContextBase
where TFeature : PersistenceFeatureBase<TFeature, TDbContext>
{
// Setup SQLite-specific handler for Entity Framework Core limitations
SetupForSqlite.AddSetupForSqliteHandler(feature.Module.Services);

feature.Module.Services.TryAddScopedImplementation<IEntityModelCreatingHandler, SetupForSqlite>();
// Configure the DbContextOptions to use SQLite
feature.DbContextOptionsBuilder = (sp, db) => db.UseElsaSqlite(migrationsAssembly, connectionStringFunc(sp), options, configure: configure);
return (TFeature)feature;
}
Expand Down