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 Chaining #62

Closed
mguinness opened this issue Mar 24, 2017 · 4 comments
Closed

OrderBy Chaining #62

mguinness opened this issue Mar 24, 2017 · 4 comments
Assignees

Comments

@mguinness
Copy link

mguinness commented Mar 24, 2017

I have some unexpected behavior (to me) regarding the OrderBy extension.

I have an existing IQueryable instance and add an order:

qry.AsExpandable().OrderBy(a => a.Inactive);

Then later on I call following statement using the extension method:

qry = qry.AsExpandable().OrderBy("Name asc");

The resulting SQL is ORDER BY Name, Inactive which seems counterintuitive, I would've expected the fields to be reversed, i.e. Inactive, Name.

Is that expected behavior? With standard LINQ to chain ordering you use OrderBy followed by ThenBy, but I don't see a ThenBy extension method in your library.

EDIT: I'm wondering if something like below is possible, either externally or internal to the library:

if (qry.Expression.Type == typeof(IOrderedQueryable<T>))
    qry = qry.ThenBy("Name asc");
else
    qry = qry.OrderBy("Name asc");
@StefH StefH self-assigned this Mar 24, 2017
@StefH
Copy link
Collaborator

StefH commented Mar 24, 2017

Interesting ! I'll take a look.

@mguinness
Copy link
Author

This SO post explains why this occurs. I was able to modify code from a blog post to create a ThenBy extension to test. I confirmed that when there is an existing sort order, you have to call ThenBy() for additional ordering. Would it be possible to include a dynamic ThenBy() extension method in your library?

StefH added a commit that referenced this issue Mar 25, 2017
StefH added a commit that referenced this issue Mar 25, 2017
@StefH
Copy link
Collaborator

StefH commented Mar 25, 2017

Should be solved. Please upgrade to latest NuGet packages.

@mguinness
Copy link
Author

Thank you, confirmed working.

@StefH StefH closed this as completed Mar 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants