SQLite provider wrapper for Bounteous.Data. It supplies
SqliteDbContextFactory<T, TUserId>, which configures EF Core's SQLite provider and inherits auditing,
soft delete, and observer support from Bounteous.Data.
Sibling packages: Bounteous.Data.SqlServer, Bounteous.Data.PostgreSQL, Bounteous.Data.MySQL.
dotnet add package Bounteous.Data.SQLitepublic class AppDbContext(
DbContextOptions options,
IDbContextObserver observer,
IIdentityProvider<Guid> identityProvider)
: DbContextBase<Guid>(options, observer, identityProvider)
{
public DbSet<Customer> Customers => Set<Customer>();
protected override void RegisterModels(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Customer>().HasKey(c => c.Id);
}using Bounteous.Data.SQLite;
public class AppDbContextFactory(
IConnectionBuilder connectionBuilder,
IDbContextObserver observer,
IIdentityProvider<Guid> identityProvider)
: SqliteDbContextFactory<AppDbContext, Guid>(connectionBuilder, observer, identityProvider)
{
protected override AppDbContext Create(DbContextOptions options, IDbContextObserver observer,
IIdentityProvider<Guid> identityProvider)
=> new(options, observer, identityProvider);
}await using var context = factory.Create();
context.Customers.Add(new Customer { Id = Guid.NewGuid(), Name = "Acme" });
await context.SaveChangesAsync(); // CreatedBy/ModifiedBy/CreatedOn set by Bounteous.Datanew DbContextOptionsBuilder<DbContextBase<TUserId>>()
.UseSqlite(ConnectionBuilder.AdminConnectionString)
.EnableSensitiveDataLogging(sensitiveDataLoggingEnabled)
.EnableDetailedErrors()
.Options;There is no EnableRetryOnFailure(), unlike the SQL Server, PostgreSQL, and MySQL wrappers. SQLite runs
in-process, so there are no transient network faults to retry, and the EF Core SQLite provider has no
retrying execution strategy.
| Scenario | Connection string |
|---|---|
| File database | Data Source=app.db |
| Read-only file | Data Source=app.db;Mode=ReadOnly |
| Private in-memory | Data Source=:memory: |
| Shared in-memory | Data Source=mydb;Mode=Memory;Cache=Shared |
An in-memory SQLite database lives only while a connection to it is open. Each factory.Create() opens
its own connection, so with Data Source=:memory: every context sees a new, empty database.
To share one in-memory database across contexts (typical for tests), use a named shared-cache database and hold one connection open for its lifetime:
const string cs = "Data Source=tests;Mode=Memory;Cache=Shared";
using var keepAlive = new SqliteConnection(cs);
keepAlive.Open();
// contexts created by a factory returning `cs` now share the same data- No
decimalordering or aggregation on the server side; EF Core storesdecimalas TEXT. Usedoubleor convert on the client if you needORDER BY/SUM. DateTimeOffsetis stored as TEXT; ordering and comparison are limited.- Schema changes are restricted (no
ALTER COLUMN); EF Core migrations rebuild tables where needed. - One writer at a time. Fine for tests, local tools, and edge/desktop apps; not a substitute for a server database under concurrent write load.
Bounteous.Data0.0.31Microsoft.EntityFrameworkCore.Sqlite10.0.14SQLitePCLRaw.bundle_e_sqlite33.0.5 (pinned so the bundled native SQLite stays ahead of the version EF Core pulls transitively)
Dependabot keeps these current.
dotnet build -c Release
dotnet test -c ReleaseTests run against real SQLite in memory. No Docker or external database needed.
MIT. See LICENSE.