Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrderBy is not fully unique #221

Open
NetanelPersik opened this issue Nov 16, 2024 · 1 comment
Open

OrderBy is not fully unique #221

NetanelPersik opened this issue Nov 16, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@NetanelPersik
Copy link

Version: 5.0.2

Expected behavior

Queries should contain fully unique OrderBy clause EF Core Pagination.

For example, if results are ordered only by date, but there can be multiple results with the same date, then results could be skipped when paginating as they're ordered differently across two paginating queries. Ordering by both date and ID (or any other unique property or combination of properties) makes the ordering fully unique and avoids this problem. Note that relational databases do not apply any ordering by default, even on the primary key.

Expected queries to allways contain orderBy PK, with priority to the specified $orderBy (if any), so if one passes:

/resource?$orderby=type desc

the expected query should be

SELECT *
FROM "TEntitiy" AS "c"
ORDER BY "c"."Type" DESC, "c"."Id" DESC

Actual behavior

When one doesn't pass any $orderBy, the expression is added with default OrderBy PK (not sure if this is by EF itself or by the library), but when one passes /resource?$orderby=type desc there is no additional orderBy by another unique column.

SELECT *
FROM "TEntitiy" AS "c"
ORDER BY "c"."Type" DESC
@BlaiseD
Copy link
Member

BlaiseD commented Nov 17, 2024

I think you're referring to this call.

You're saying:

  • Order by PK when no $orderby is specified.
  • If and an $orderby is specified still make order by PK the last ThenBy call.

Ok to submit a PR.

@BlaiseD BlaiseD added the enhancement New feature or request label Nov 17, 2024
NetanelPersik pushed a commit to NetanelPersik/AutoMapper.Extensions.OData that referenced this issue Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants