specification-pattern

Encapsulate EF Core query logic into reusable, composable specifications with criteria, includes ordering and paging.

69|13|Updated Jan 26, 2026
One-click install
npx skills add https://github.com/ronnythedev/dotnet-clean-architecture-skills --skill specification-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: specification-pattern
Source: https://github.com/ronnythedev/dotnet-clean-architecture-skills/tree/main/sample/POS/.claude/skills/20-specification-pattern
Command: npx skills add https://github.com/ronnythedev/dotnet-clean-architecture-skills --skill specification-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The Specification pattern encapsulates query logic into reusable, composable, and testable building blocks for EF Core, centralizing criteria, includes, ordering, and paging.

Core Features & Use Cases

  • Reusable criteria: define and reuse filters across repositories.
  • Includes and paging: specify eager loading and page-sized results consistently.
  • Order by support: apply deterministic sorting for stable results.
  • Use Case: fetch a paged list of active entities for a given organization with optional includes.

Quick Start

Create a concrete specification by extending BaseSpecification<T>, add criteria via AddCriteria, attach includes with AddInclude, and apply paging with ApplyPaging. Then pass the specification to a repository that uses SpecificationEvaluator to execute the query.

Frequently Asked Questions about specification-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I encapsulate EF Core query logic into reusable components?

To encapsulate EF Core query logic, extend BaseSpecification<T>, define criteria with AddCriteria, attach includes with AddInclude, and pass the specification to a repository using SpecificationEvaluator.

What is the specification pattern for EF Core data access?

The specification pattern for EF Core centralizes query criteria, eager loading includes, ordering, and paging into composable, testable building blocks applied consistently across aggregates.

How do I apply paging and eager loading in EF Core queries consistently?

You apply paging and eager loading consistently by using ApplyPaging and AddInclude within a BaseSpecification<T>, then executing the query through SpecificationEvaluator.

Can I compose and test EF Core query specifications across different repositories?

Yes, specifications encapsulate query logic into reusable building blocks that can be composed and tested independently, allowing you to define and reuse filters across multiple EF Core repositories.

What is the best way to fetch a paged list of active entities with optional includes in EF Core?

The best way is to create a concrete specification extending BaseSpecification<T>, apply criteria for active entities, use ApplyPaging, attach optional includes, and execute via SpecificationEvaluator.

Related Skills