Skip to content

Brief: EF Core 10 relational provider for DuckDB (for Cedric)

You are Cedric Jones-Gaffney (Codex), implementing. Clahadore (Claude) orchestrates and reviews.

Goal

A reusable C# library, EFCore.DuckDB (NuGet id JonesGaffney.EntityFrameworkCore.DuckDB, root namespace JonesGaffney.EntityFrameworkCore.DuckDB). It is a real read/write EF Core relational provider for DuckDB, built on the ADO.NET driver DuckDB.NET.Data.Full 1.5.6.1 (bundles DuckDB 1.5.6). Target net10.0, EF Core 10.0.14 (Microsoft.EntityFrameworkCore.Relational). Its first consumer is Verse4Verse (accounts, annotations, moderation decisions, studies, catalog, Scripture metadata). The database is reached either as a local file, in memory, or through DuckDB's Quack remote protocol.

Must have (v0.1, in this order)

  1. UseDuckDB(connectionString, o => ...) options extension, plus service registration (AddEntityFrameworkDuckDB), DuckDBOptionsExtension, connection (DuckDBRelationalConnection) and DuckDBDatabaseCreator (Exists/Create/Delete for file + in-memory; HasTables).
  2. Type mappings: bool, sbyte/short/int/long, byte/ushort/uint/ulong (UTINYINT..UBIGINT), float, double, decimal(p,s), string (VARCHAR), byte[] (BLOB), Guid (UUID), DateTime (TIMESTAMP), DateTimeOffset (TIMESTAMPTZ), DateOnly (DATE), TimeOnly (TIME), TimeSpan (INTERVAL), enums via value conversion. Literal generation for each type must round-trip.
  3. SQL generation (DuckDBQuerySqlGenerator, DuckDBSqlGenerationHelper): double-quoted identifiers, LIMIT/OFFSET, || concat, ILIKE not needed, boolean literals TRUE/FALSE, parameters $1-style or ? (match whatever DuckDB.NET supports; check its docs/tests), CAST(x AS type).
  4. Method/member translators: string Contains/StartsWith/EndsWith/ToLower/ToUpper/Trim/Length/Substring/ Replace/IsNullOrEmpty, Math Abs/Round/Floor/Ceiling/Max/Min, DateTime.Now/UtcNow/Year/Month/Day, Guid.NewGuid → uuid(), EF.Functions.Like.
  5. Updates (DuckDBUpdateSqlGenerator): INSERT/UPDATE/DELETE with RETURNING for store-generated values; identity via SEQUENCE + DEFAULT nextval('seq') (DuckDB has no SERIAL/IDENTITY), generated per key in migrations. Optimistic concurrency tokens must work (rows-affected check). Transactions: DuckDB MVCC; savepoints are NOT supported by DuckDB — disable them cleanly (SupportsSavepoints => false / override so SaveChanges doesn't emit SAVEPOINT).
  6. Migrations: DuckDBMigrationsSqlGenerator (CreateTable, DropTable, AddColumn, DropColumn, RenameColumn, RenameTable, CreateIndex, DropIndex, EnsureSchema, sequences, AddForeignKey as part of CREATE TABLE only — DuckDB cannot ALTER TABLE ADD CONSTRAINT FK; throw a clear NotSupportedException otherwise), DuckDBHistoryRepository (__EFMigrationsHistory), and a migrations lock compatible with EF 10 (IMigrationsDatabaseLock; use a lock table, since DuckDB has no advisory locks). Note: Verse4Verse will ALSO keep forward-only versioned SQL migrations in git; EF migrations must be scriptable (dotnet ef migrations script --idempotent) so they can be reviewed and run as a job.
  7. Quack support: a documented way to point a context at a Quack server. Approach: open an in-memory DuckDB connection, then run ATTACH 'quack:<host>' AS app (TOKEN '<token>'); USE app; on open via a DbConnectionInterceptor exposed as o.UseQuack(uri, token). Token never logged. Integration test it only if a local Quack server is available (QUACK_TEST_URI env); skip otherwise.

Tests (xunit, in tests/)

  • Unit tests for type mapping literals and SQL generation (golden SQL strings).
  • Functional tests against in-memory DuckDB: a small blog/posts/tags model covering CRUD, includes, owned types, value conversions, concurrency token conflict, transactions, migrations up from empty, EnsureCreated, and LINQ translations listed above. Assert real results, not just "no exception".
  • If time permits, wire a subset of Microsoft.EntityFrameworkCore.Relational.Specification.Tests and report the pass rate.

Rules

  • C#. No other language. Small, readable classes mirroring the structure of the Npgsql/Sqlite providers.
  • Check DuckDB SQL facts against the DuckDB docs (https://duckdb.org/docs/) when unsure; don't guess.
  • Don't run anything that opens a visible window. Builds/tests with dotnet build/dotnet test.
  • This PC is under memory pressure: build serially, -m:1, no parallel test hosts beyond default.
  • git init is done; commit in small logical commits on branch main with messages EFCore.DuckDB: <what>. Do NOT push, do NOT create a GitHub repo.
  • License header: none yet (license is Andrew's decision); add LICENSE-PENDING.md noting that.

Done means

dotnet build -c Release and dotnet test -c Release pass, and README.md documents usage, the type map, what is and isn't supported (savepoints, FK alter), and the Quack setup. End your run with a summary: commits, test counts (passed/failed/skipped), and the not-yet-supported list.