<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/dynamic-filtering-sorting-and-pagination-with-specifications-drb7w0tsk" -->

---
title: Dynamic Filtering, Sorting, and Pagination With...
description: A detailed walkthrough builds a safe, allowlisted query envelope for dynamic filtering, sorting, and pagination with EF Core 10.0.10 and .NET 10, avoiding...
canonical: https://daily.dev/posts/dynamic-filtering-sorting-and-pagination-with-specifications-drb7w0tsk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Dynamic Filtering, Sorting, and Pagination With Specifications | daily.dev
og:description: A detailed walkthrough builds a safe, allowlisted query envelope for dynamic filtering, sorting, and pagination with EF Core 10.0.10 and .NET 10, avoiding...
og:url: https://daily.dev/posts/dynamic-filtering-sorting-and-pagination-with-specifications-drb7w0tsk
og:image: https://api.daily.dev/og/posts/drb7W0tsk.png
og:image:alt: Dynamic Filtering, Sorting, and Pagination With Specifications
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Dynamic Filtering, Sorting, and Pagination With Specifications

**[We Are .NET](https://daily.dev/sources/wearedotnet)** · 19 min read · 5 upvotes · 0 comments

## Summary

A detailed walkthrough builds a safe, allowlisted query envelope for dynamic filtering, sorting, and pagination with EF Core 10.0.10 and .NET 10, avoiding arbitrary reflection-based OrderBy or user-supplied expression trees. It covers a validated ProductSearchSpecification with an enum-backed sort allowlist, offset pagination via Skip/Take, keyset (seek) pagination with cursors, optional exact total counts, cancellation token propagation, and the importance of fully unique ordering with a tie-breaker column. SQLite-based relational tests verify translation, deterministic ordering, and reader command counts, while the piece stresses that production-provider behavior (collation, indexes, SQL shape) still needs separate validation.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.devleader.ca/2026/09/14/dynamic-filtering-sorting-and-pagination-with-specifications>

## Questions this post answers

### Why should I avoid building OrderBy dynamically with reflection based on a client-supplied property name in EF Core?

Reflection-based OrderBy broadens the public query surface and makes translation and deterministic ordering harder to reason about. An allowlisted switch statement instead gives each supported sort known type semantics, a fixed direction, a guaranteed tie-breaker column, matching indexes, and dedicated tests, keeping every possible query shape reviewable and testable.

_daily.dev surfaces practical patterns like this for developers hardening query APIs against unsafe dynamic input._

### Does compiling a LINQ expression predicate make EF Core queries run faster?

No, compiling an expression tree into a delegate actually removes the tree EF Core needs for provider translation, so it should be avoided for database queries. Compiled delegates only make sense for isolated in-memory execution or tests; production EF Core filtering should keep predicates as Expression<Func<T,bool>> on IQueryable<T> so the provider can translate them to SQL.

_developers optimizing EF Core query performance can track this kind of guidance on daily.dev._

### Why does pagination in EF Core need a fully unique ordering instead of just sorting by one column like name or price?

Because relational databases do not automatically add primary-key ordering, sorting by a single non-unique column like Name or Price can produce inconsistent or duplicated rows across pages when multiple rows share that value. Appending Id as a tie-breaker after every primary sort field (Name+Id, Price+Id, CreatedSequence+Id) makes the ordering deterministic for both offset and keyset pagination.

_anyone building reliable paginated APIs can follow evolving EF Core pagination practices on daily.dev._

## Similar posts on daily.dev

- [Pagination in EF Core, Continued: Sortable Grids, htmx, and the Indexing Cost - Chris Woody Woodruff](https://daily.dev/posts/pagination-in-ef-core-continued-sortable-grids-htmx-and-the-indexing-cost---chris-woody-woodruff-rqtvmyrpl) · We Are .NET · 1 upvotes · 0 comments
- [How to Fix Slow EF Core Queries: Practical Performance Tuning](https://daily.dev/posts/how-to-fix-slow-ef-core-queries-practical-performance-tuning-effrdqtga) · Syncfusion · 38 upvotes · 0 comments
- [Offset, Keyset, and Cursor Pagination in .NET: When to Use Each](https://daily.dev/posts/offset-keyset-and-cursor-pagination-in-net-when-to-use-each-nu8z07czy) · Waseem .NET Newsletter · 12 upvotes · 2 comments
- [Specification Pattern in C\#: A Practical Guide for Modern .NET](https://daily.dev/posts/specification-pattern-in-c-a-practical-guide-for-modern-net-rwptpwhx7) · We Are .NET · 8 upvotes · 1 comments
- [What’s New with APIs in .NET 10: Real Improvements](https://daily.dev/posts/what-s-new-with-apis-in-net-10-real-improvements-eq1nq18pb) · Telerik · 40 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/dynamic-filtering-sorting-and-pagination-with-specifications-drb7w0tsk)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Dynamic Filtering, Sorting, and Pagination With Specifications","url":"https://daily.dev/posts/dynamic-filtering-sorting-and-pagination-with-specifications-drb7w0tsk","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/dynamic-filtering-sorting-and-pagination-with-specifications-drb7w0tsk"},"datePublished":"2026-09-14T14:17:05.355Z","dateModified":"2026-09-14T14:17:31.099Z","description":"A detailed walkthrough builds a safe, allowlisted query envelope for dynamic filtering, sorting, and pagination with EF Core 10.0.10 and .NET 10, avoiding...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5e18e36d8bd8a158f9543f3fffb131f5?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5e18e36d8bd8a158f9543f3fffb131f5?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"We Are .NET","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"We Are .NET","logo":"https://media.daily.dev/image/upload/s--BsnVOa3i--/f_auto/v1718347410/logos/wearedotnet","url":"https://daily.dev/sources/wearedotnet"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/dynamic-filtering-sorting-and-pagination-with-specifications-drb7w0tsk","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":5},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#","timeRequired":"PT19M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"We Are .NET","item":"https://daily.dev/sources/wearedotnet"},{"@type":"ListItem","position":3,"name":"Dynamic Filtering, Sorting, and Pagination With Specifications"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/dynamic-filtering-sorting-and-pagination-with-specifications-drb7w0tsk#faq","mainEntity":[{"@type":"Question","name":"Why should I avoid building OrderBy dynamically with reflection based on a client-supplied property name in EF Core?","acceptedAnswer":{"@type":"Answer","text":"Reflection-based OrderBy broadens the public query surface and makes translation and deterministic ordering harder to reason about. An allowlisted switch statement instead gives each supported sort known type semantics, a fixed direction, a guaranteed tie-breaker column, matching indexes, and dedicated tests, keeping every possible query shape reviewable and testable. daily.dev surfaces practical patterns like this for developers hardening query APIs against unsafe dynamic input."}},{"@type":"Question","name":"Does compiling a LINQ expression predicate make EF Core queries run faster?","acceptedAnswer":{"@type":"Answer","text":"No, compiling an expression tree into a delegate actually removes the tree EF Core needs for provider translation, so it should be avoided for database queries. Compiled delegates only make sense for isolated in-memory execution or tests; production EF Core filtering should keep predicates as Expression\u003cFunc\u003cT,bool\u003e\u003e on IQueryable\u003cT\u003e so the provider can translate them to SQL. developers optimizing EF Core query performance can track this kind of guidance on daily.dev."}},{"@type":"Question","name":"Why does pagination in EF Core need a fully unique ordering instead of just sorting by one column like name or price?","acceptedAnswer":{"@type":"Answer","text":"Because relational databases do not automatically add primary-key ordering, sorting by a single non-unique column like Name or Price can produce inconsistent or duplicated rows across pages when multiple rows share that value. Appending Id as a tie-breaker after every primary sort field (Name+Id, Price+Id, CreatedSequence+Id) makes the ordering deterministic for both offset and keyset pagination. anyone building reliable paginated APIs can follow evolving EF Core pagination practices on daily.dev."}}]}
```

