Add query-plan (Specification pattern) support for EF Core#2526
Merged
jeremydmiller merged 1 commit intomainfrom Apr 17, 2026
Merged
Add query-plan (Specification pattern) support for EF Core#2526jeremydmiller merged 1 commit intomainfrom
jeremydmiller merged 1 commit intomainfrom
Conversation
Introduces Wolverine.EntityFrameworkCore.IQueryPlan<TDbContext, TResult>, QueryPlan<TDb, TEntity>, and QueryListPlan<TDb, TEntity>. This is the Specification pattern implemented as a first-class concept, patterned after Marten's IQueryPlan and Ardalis.Specification. Motivation: handlers often need queries richer than a primary-key lookup (which [Entity] already covers) but not complex enough to justify a repository layer. A query plan lets authors encapsulate reusable LINQ over a DbContext in its own testable class. Phase 1 scope: - Base types in Wolverine.EntityFrameworkCore.QueryPlans - QueryByPlanAsync extension on DbContext (parallels Marten's IQuerySession.QueryByPlanAsync) - Zero code-generation — plans are plain classes, no DI, no reflection, no source generators - 9 unit tests against the EF Core in-memory provider - 1 end-to-end integration test using SQL Server + Wolverine's transactional middleware - New documentation page: docs/guide/durability/efcore/query-plans.md Deferred to follow-up: [FromQueryPlan(typeof(TPlan))] parameter attribute that constructs the plan from message fields at codegen time, mirroring how [Entity] resolves its identity. Closes #2505 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
8 tasks
Merged
13 tasks
This was referenced Apr 21, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1 of #2505. Introduces
Wolverine.EntityFrameworkCore.IQueryPlan<TDbContext, TResult>plus convenience base classes — the Specification pattern implemented as a first-class concept, patterned after Marten's IQueryPlan and Ardalis.Specification.This fills the gap between
[Entity](primary-key lookup only) and a full repository/adapter layer. Handlers can now encapsulate reusable LINQ over aDbContextin a testable class, without any code generation or DI plumbing.API
User code
Design notes
IQueryPlan/QueryPlan/QueryListPlan) rather thanISpecification— consistency inside the Critter Stack wins, and avoids conflict with users already using Ardalis.SpecificationIQueryable<T>surface — no custom DSL to learn.Include,OrderBy,Select,Skip,Take, projection to DTOs all workDbContextthe handler receives (already tenant-scoped by existing middleware)Out of scope (deferred to follow-up)
[FromQueryPlan(typeof(TPlan))]parameter attribute that constructs the plan from message fields at codegen time (mirrors how[Entity]resolves its identity). Worth its own PR once the core shape is settled.BatchedLoadEntityFrameinfrastructure is the template)Files
src/Persistence/Wolverine.EntityFrameworkCore/QueryPlans/:IQueryPlan.cs,QueryPlan.cs,QueryListPlan.cs,QueryPlanExtensions.cssrc/Persistence/EfCoreTests/QueryPlans/:QueryPlan_specs.cs(9 unit tests),QueryPlan_end_to_end.cs(1 SQL Server integration test)docs/guide/durability/efcore/query-plans.md+ nav entry in.vitepress/config.mtsTest plan
SaveChangesAsynccommits the mutations the plan's results triggeredbatch_query_tests+end_to_end_efcore_persistencetests still pass (no regressions)🤖 Generated with Claude Code