[CSHARP-3965] OrderBy with an expression that doesn't resolve to a field is not supported Created: 11/Nov/21 Updated: 01/Nov/22 Resolved: 01/Nov/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | LINQ3 |
| Affects Version/s: | 2.13.2 |
| Fix Version/s: | 2.19.0 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Rick van Lieshout | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 8 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||
| Issue Links: |
|
||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||
| Description |
|
When compiling a Queryable with an order-by expression that uses null-coalescing to default(T) errors are thrown during execution. I've attached a picture with one of our queries that results in an error. 2022-11-12: See comment below for a minimal reproduction. |
| Comments |
| Comment by Githook User [ 01/Nov/22 ] | ||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: | ||||||||||||||||||||||||||||||||||||||||
| Comment by James Kovacs [ 26/Jan/22 ] | ||||||||||||||||||||||||||||||||||||||||
|
Hi, Rick, Thanks for reaching out again. This enhancement has not been prioritized yet compared to other work in our backlog. Please feel free to upvote the issue as we do take votes into account when prioritizing new feature requests. James | ||||||||||||||||||||||||||||||||||||||||
| Comment by Rick van Lieshout [ 26/Jan/22 ] | ||||||||||||||||||||||||||||||||||||||||
|
Any updates perhaps? | ||||||||||||||||||||||||||||||||||||||||
| Comment by Rick van Lieshout [ 12/Nov/21 ] | ||||||||||||||||||||||||||||||||||||||||
|
Hey Robert, I also feel that the driver should support the use-case | ||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 12/Nov/21 ] | ||||||||||||||||||||||||||||||||||||||||
|
Reopening this ticket because the workaround proposed could actually be implemented internally by the LINQ provider itself. For example:
Using `_key1` as the name of the key to sort by allows for adding additional sort keys (`_key2` etc...) if `ThenBy` methods are part of the LINQ expression. | ||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 12/Nov/21 ] | ||||||||||||||||||||||||||||||||||||||||
|
This is due to how the server $sort stage works. The $sort stage can only sort documents by fields, not by arbitrary computed expressions. See: https://docs.mongodb.com/manual/reference/operator/aggregation/sort I used the following class to reproduce this exception as simply as possible:
The following test reproduces what you are seeing:
You can work around this server limitation by creating a temporary field set to the value you want to sort by. NOTE: because of limitations in the current LINQ implementation (known as LINQ2) this workaround only works with the new LINQ implementation (known as LINQ3). LINQ3 is available in beta form in the 2.14.0-beta1 version of the driver. For example:
|