[CSHARP-1463] OrderBy DateTime Created: 30/Oct/15 Updated: 14/Mar/23 Resolved: 04/Nov/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq, Serialization |
| Affects Version/s: | 2.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Miguel Ángel Arilla | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | Bug | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
I tried several times to sort by a DateTime field and throws the NotSupportedException, only fields allowed in a $sort. I explained it with more details here: |
| Comments |
| Comment by Valentin Levshits [ 14/Mar/23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Issue is actual again in MongoDB Driver 2.19. Works fine in 2.18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Miguel Ángel Arilla [ 04/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Works smoothly. Thanks, Miguel. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 04/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks so much Miguel... I just fixed something very similar to this in Craig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Miguel Ángel Arilla [ 04/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I finally managed to reproduce the error with your snippet, the thing is that I developed a wrapper for the mongodb driver to integrate it in our DDD architecture, and some complex queries are passed through a custom object.
If i introduce this change to the snippet, the test fails.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 03/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I tried on .NET 4.5 all the way through 4.6 as well. Anyways... let me know what you find. Thanks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Miguel Ángel Arilla [ 03/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
We are currently using .NET framework 4.6, it may be the cause since its new. I'll try the code tomorrow early. Thank you very much for your effort, Miguel. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 03/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Miguel, I fully understand the problem you are indicating, but simply can't make it reproduce in any tests. What version of the .NET framework are you using? Below is a simple console application that is working based on your sample above. I've also done the querying 2 different ways and can't make it reproduce.
Let me know if this reproduces for you. If not, perhaps you could try and tweak it to make it happen. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 03/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks Miguel. Yes, I understand the problem. I simply wasn't able to make a test fail because of this. I even tried what you did above. I'll make another attempt today. Perhaps I did something subtly different in my attempt. I'll try again. Also, thanks for the conventions. There isn't any reason the conventions should affect this, but I'll look into that angle as well if I can't repro. Craig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Miguel Ángel Arilla [ 03/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In case this also causes any kind of internal issues when trying to sort, I got a second custom convention that simply translates the notation of .NET entities, like {{ public string SomeField }} to some_field.
Where Mongify is the method that converts the string (just some char play). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Miguel Ángel Arilla [ 03/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi, The code structure is pretty basic, but I have a custom convention related to datetime.
the operation is _collection.AsQueryable().OrderByDescending(x => x.SampleDate) I post the custom convention in case it's the problem.
It may be due to the internal cast "Convert" that the expression tree performs on the field. (as explained in the stackoverflow link, with a possible fix too) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 02/Nov/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Miguel Arilla, I have attempted a couple of different ways to make this reproduce. Could you provide a reproducible sample I can use? I'd love to fix this problem. Thanks, |