specification-pattern

Implements reusable ISpecification<T> pattern for .NET and Entity Framework data queries.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill specification-pattern-faysilalshareef
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: specification-pattern
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/data/specification-pattern
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill specification-pattern-faysilalshareef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The specification pattern centralizes and composes complex query logic outside repositories so repositories stay thin, query intent is explicit, and query reuse is simplified across the codebase.

Core Features & Use Cases

  • Expression-based Criteria: Define Criteria as expression trees to enable IQueryable filtering and provider translation.
  • Includes and IncludeStrings: Support eager-loading via typed include expressions or string paths for flexible navigation property loading.
  • Ordering and Paging: Encapsulate OrderBy/OrderByDescending and Skip/Take pagination in reusable specifications.
  • Use Case: Create an ActiveOrdersByCustomerSpec to filter active orders, include line items, sort by creation date, and paginate results for a customer-facing API.

Quick Start

Add a specification class for your entity and pass it to your repository's ListAsync or GetBySpecAsync to filter, include, order and paginate results.

Frequently Asked Questions about specification-pattern

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

FAQPage Schema
How do I compose query criteria for EF Core without bloating my repository?

The specification pattern lets you compose query criteria outside your repository by defining expression-based filters, includes, and pagination. This keeps repositories thin and makes query intent explicit and reusable across your .NET application code.

How do I implement eager loading and pagination on IQueryable data in .NET?

You can implement eager loading and pagination on IQueryable data by defining a specification class with typed Include expressions and Skip/Take properties. Pass this specification to your repository methods to apply the composed query criteria directly to your EF Core data provider.

What is the specification pattern in domain-driven design?

The specification pattern in domain-driven design is a reusable abstraction that encapsulates complex query logic for domain entities. It allows you to define expression-based criteria, ordering, and eager-loading rules that can be composed and applied to IQueryable data in your repository layer.

Can I use string paths for navigation property loading in EF Core specifications?

Yes, you can use string paths for navigation property loading. The implementation supports both typed include expressions and IncludeStrings, providing flexible options for eager-loading navigation properties when defining your query specifications.

Does this specification pattern implementation support sorting and ordering?

Yes, the specification pattern implementation supports sorting through OrderBy and OrderByDescending properties. You can encapsulate sorting logic alongside filtering, eager-loading, and pagination within a single reusable specification class for your domain entities.

What are the limitations of using expression trees for EF Core query composition?

When using expression trees for EF Core query composition, you are constrained by what the database provider can translate. Complex criteria or unsupported methods in your expression-based specifications may not translate to valid SQL, limiting their use in infrastructure code.