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

Support for ORDER BY CASE WHEN? #1236

Open
cjfarr opened this issue Jun 26, 2024 · 1 comment
Open

Support for ORDER BY CASE WHEN? #1236

cjfarr opened this issue Jun 26, 2024 · 1 comment

Comments

@cjfarr
Copy link

cjfarr commented Jun 26, 2024

I have a use case that does not appear to be supported. Please observe this example:

var query = SQLiteConnection.Table<MyClass>()
              .OrderBy(x => x.SomeProperty == "Preferred Value" && x.AnotherProperty == "2nd Preferred")
              .ThenBy(x => x.SomeProperty)
              .ThenBy(x => x.AnotherProperty);

If I were to write this in plain SQL for a tool such as DBeaver it would look like this:

ORDER BY
CASE WHEN 
SomeProperty = 'Preferred Value' AND AnotherProperty = '2nd Preferred'
THEN 0 ELSE 1 
END ASC,
SomeProperty ASC,
AnotherProperty ASC

When I try to run the C# code I get a System.NotSupportedException: 'Order By does not support: [I believe this is the Expression.ToString() from the first OrderBy function in the C# code]. If there is a different way to achieve this sort or have I missed something? Please let me know. Otherwise, could we consider supporting something like this?

Thanks.

@cjfarr
Copy link
Author

cjfarr commented Jun 27, 2024

Adding more info. One of my customers wants a list of work sites ordered by a secondary id then a primary id. However, they want an exception to this sort where the users default work site sits on top.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant