Skip to content

Adopt Weasel IDatabaseCleaner<T> and BatchedQuery EF Core APIs (#2473, #2478)#2492

Merged
jeremydmiller merged 1 commit intomainfrom
feature/2473-2478-weasel-efcore-cleaner-and-batch-query
Apr 9, 2026
Merged

Adopt Weasel IDatabaseCleaner<T> and BatchedQuery EF Core APIs (#2473, #2478)#2492
jeremydmiller merged 1 commit intomainfrom
feature/2473-2478-weasel-efcore-cleaner-and-batch-query

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

Closes #2473 and #2478.

#2473 – IDatabaseCleaner<TContext> in EF Core integration tests

Adopts Weasel 8.13.0's IDatabaseCleaner<TContext> and IInitialData<TContext> APIs to replace ad-hoc manual cleanup code in integration tests.

  • database_cleaner_tests.cs – new integration-test file demonstrating:
    • services.AddDatabaseCleaner<ItemsDbContext>() (singleton, discovers tables from DbContext.Model, generates FK-safe deletion SQL: TRUNCATE CASCADE on PostgreSQL, DELETE FROM on SQL Server)
    • services.AddInitialData<ItemsDbContext, SeedItemsForTests>() for seed data that re-runs after ResetAllDataAsync()
    • Tests for DeleteAllDataAsync() (clears all rows) and ResetAllDataAsync() (clears then re-seeds)

#2478 – Weasel BatchedQuery codegen infrastructure

Adds the code-generation frames and integration tests for Weasel's BatchedQuery API, which batches multiple EF Core SELECT queries into a single database round trip.

  • BatchedLoadEntityFrameSyncFrame that enqueues a batch.QuerySingle(context.Set<T>().Where(…)) into a shared BatchedQuery instead of calling DbContext.FindAsync. Participates in a shared batch when a CreateBatchQueryFrame is upstream.
  • CreateBatchQueryFrame – inserts a var batchQuery = context.CreateBatchQuery() variable that downstream load frames share.
  • ExecuteBatchQueryFrame – issues await batchQuery.ExecuteAsync(ct) and then awaits each pending entity Task.
  • batch_query_tests.cs – integration tests against SQL Server showing:
    • Two QuerySingle calls in one round trip
    • Query<T> list loading in a batch
    • Mixed single + list queries in the same batch
    • Unit tests for all three new codegen frame types

Test plan

  • EfCoreTests project builds cleanly (dotnet build --framework net9.0)
  • database_cleaner_usage_tests integration tests pass against SQL Server (requires docker compose up -d)
  • batch_query_tests integration tests pass against SQL Server
  • batched_load_entity_frame_codegen_tests unit tests pass without infrastructure

🤖 Generated with Claude Code

…ion (#2473, #2478)

Issue #2473 – IDatabaseCleaner<TContext> / IInitialData<TContext>:
- Add database_cleaner_tests.cs demonstrating IDatabaseCleaner<ItemsDbContext>
  registered via services.AddDatabaseCleaner<T>() and used in tests to replace
  manual DELETE FROM / schema-drop cleanup code.
- Add SeedItemsForTests implementing IInitialData<ItemsDbContext> to show
  the recommended seed-data pattern with ResetAllDataAsync().

Issue #2478 – Weasel BatchedQuery codegen infrastructure:
- Add BatchedLoadEntityFrame: SyncFrame that queues a QuerySingle() into a
  shared BatchedQuery instead of calling DbContext.FindAsync, enabling future
  multi-entity loads in a single round trip.
- Add CreateBatchQueryFrame: inserts a shared BatchedQuery variable that
  BatchedLoadEntityFrame instances can share.
- Add ExecuteBatchQueryFrame: executes the batch and awaits each entity Task.
- Add batch_query_tests.cs with integration tests demonstrating CreateBatchQuery()
  for loading two entities, a list, and mixed single+list in one round trip,
  plus unit tests for the three new codegen frame types.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit 94b80c6 into main Apr 9, 2026
12 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adopt Weasel's new IDatabaseCleaner<T> in EF Core integration tests

1 participant