-
Notifications
You must be signed in to change notification settings - Fork 57
Make orderBy unique for paging. #222
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| namespace AutoMapper.AspNet.OData | ||
| using Microsoft.OData.UriParser; | ||
|
|
||
| namespace AutoMapper.AspNet.OData | ||
| { | ||
| internal class OrderBySetting | ||
| { | ||
| public string Name { get; set; } | ||
| public OrderByDirection Direction { get; set; } = OrderByDirection.Ascending; | ||
| public OrderBySetting ThenBy { get; set; } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic did not create the
OrderByif there were no related methodsTop,Skipetc... Why did that have to go?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we don't want to return null on
NoQueryableMethodwe always need to append some orderBy: #221There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree.
Microsoft.AspNetCore.OData.Query.EnableQueryAttributedoes not sort by default either which leads me think that the logic enforcing the "ThenBy PK" sort really belongs in your own code. We should close this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before closing this, just want to point out few things:
OrderByeven when it was not requested at all.OrderBywe appendThenByPK as wellGetQueryAsyncsince EF apply theorderByafter the LIMIT which ruins the point:Keyset Paginationhttps://google.aip.dev/158Maybe we can settle for 2. ("When one passes some
OrderBywe appendThenByPK as well")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the other way round. Changing the code needs justification - leaving it untouched doesn't.
Adding the
ThenByto your request when necessary is better. Then it does not have to run for users who are not requesting it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to add
thenBypk to requests containing $orderBy=notPkSo if the request looks like this:
"/corebuilding?$top=5&$expand=Builder($expand=City),Tenant&$orderby=Name desc"
We want it to look like this:
"/corebuilding?$top=5&$expand=Builder($expand=City),Tenant&$orderby=Name desc,Identity";
Notice we chained
Identityto theorderByto make it unique in caseorderBy=Namewill return duplicates (sinceNameis not unique)That way paging will be consistent...
Databases will return random order for duplicate values...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct - just do this:
"/corebuilding?$top=5&$expand=Builder($expand=City),Tenant&$orderby=Name desc,Identity";Otherwise we'd be adding theThenByfor every user on every request.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO adding thenBy pk on every request is best practice.
I don't want the consistency of my paging depending on customers (whether they pass Identity or not) also notice I don't change the request itself, it is immutable, internally im taking care of adding thenBy...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work if we add an opt-in flag to ODataSettings. Something like
ODataSettings.AlwaysSortByPrimaryKeythen we can do both behaviors when that flag is set (PK sort whenNoQueryableMethodplus theThenByPK) .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!