query-patterns

Implement GET endpoints with pagination, filtering, sorting, and DTO mapping.

6.7k|2.0k|Updated Aug 20, 2021
One-click install
npx skills add https://github.com/fullstackhero/dotnet-starter-kit --skill query-patterns-fullstackhero
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: query-patterns
Source: https://github.com/fullstackhero/dotnet-starter-kit/tree/main/.agents/skills/query-patterns
Command: npx skills add https://github.com/fullstackhero/dotnet-starter-kit --skill query-patterns-fullstackhero

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Query-patterns helps you implement consistent and efficient read (GET) endpoints for a modular .NET backend without inventing a new pagination, sorting, or DTO-mapping approach each time.

Core Features & Use Cases

  • Paginated search lists: Implements filter, search, sorting, and pagination returning PagedResponse<T> with computed TotalCount and TotalPages.
  • Single-entity fetch: Implements by-id reads with AsNoTracking and a standardized NotFoundException when missing.
  • Production-ready endpoint wiring: Uses MediatR-style handlers and endpoint mappings that enforce permissions and bind query parameters cleanly.
  • Guardrails & conventions: Encourages DTO projection via .ToDto(), relies on tenant + soft-delete filters automatically, and uses validators for page parameters.

Quick Start

Use this skill to add a GET endpoint that returns either a paginated search result or a single DTO by id, following the provided IQueryable + PagedResponse conventions and wiring pattern.

Frequently Asked Questions about query-patterns

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

FAQPage Schema
How do I implement paginated search endpoints in .NET without repeating filter logic?

To implement paginated search endpoints in .NET, apply LINQ filtering and sorting on your DbContext, then map results to a PagedResponse<T> DTO with computed TotalCount and TotalPages. This enforces consistent pagination conventions without repeating filter logic.

What is the best way to handle single-entity retrieval with Entity Framework Core and LINQ?

The best way to handle single-entity retrieval is using AsNoTracking on your DbContext LINQ query to prevent change tracking overhead. If the entity is missing, a standardized NotFoundException is thrown to handle missing records cleanly.

Does this .NET query pattern support multitenancy and soft-delete filtering automatically?

Yes, this query pattern relies on automatic tenant and soft-delete filters within the module DbContext. You do not need to manually re-filter queries for multitenancy or soft-deleted records when building vertical-slice GET handlers.

Can I use MediatR for wiring GET endpoints that return paginated DTOs?

Yes, you can use MediatR-style handlers and endpoint mappings to wire GET endpoints. This approach enforces permissions, binds query parameters cleanly, and validates page parameters before returning your paginated DTOs.

How do I validate page parameters for paginated list queries in a .NET API?

Validating page parameters for paginated list queries uses dedicated validators within the MediatR-style endpoint pipeline. This ensures page size and number are checked before the DbContext LINQ query executes and computes total counts.

When should I use AsNoTracking in my .NET read endpoints?

You should use AsNoTracking in .NET read endpoints when fetching single entities or building paginated search lists. It enforces read-only behavior, improves performance by skipping change tracking, and is standard for GET endpoint query patterns.