[CSHARP-4743] Add support for DateTime.Date and DateTime.TimeOfDay Created: 02/Aug/23 Updated: 24/Aug/23 Resolved: 09/Aug/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | API |
| Affects Version/s: | 2.20.0 |
| Fix Version/s: | 2.21.0 |
| Type: | Improvement | Priority: | Unknown |
| Reporter: | Sasan Pasha | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | Bug | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Documentation Changes: | Not Needed | ||||||||||||||||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
||||||||||||||||
| Description |
Summarydoing a linq query on datetime.year results in an exception :Serializer for System.DateTime must implement IBsonDocumentSerializer to be used with LINQ. Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).How to Reproduceexample: var interactions = await (await EquipmentInteractionsCollection.AsQueryable() Additional BackgroundI think this issue was brought in story |
| Comments |
| Comment by Githook User [ 09/Aug/23 ] |
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: |
| Comment by Robert Stam [ 07/Aug/23 ] |
|
When using `DateTime.Date` and `DateTime.TimeOfDay` keep in mind that `DateTime` values are stored in UTC on the server and that these operations will be done on UTC values. |
| Comment by Robert Stam [ 07/Aug/23 ] |
|
While we support most DateTime properties, we missed adding support for `Date` and `TimeOfDay`. I am adding support for those now. |
| Comment by Sasan Pasha [ 07/Aug/23 ] |
|
Hi robert@mongodb.com . my apologies - you are correct, It's for the Date query. |
| Comment by Robert Stam [ 07/Aug/23 ] |
|
Your sample code works for me when using `b.InteractionDate.Value.Year` but when using `b.InteractionDate.Value.Date` I get an exception. I'm updating the summary to mention `DateTime.Date` instead of `DateTime.Year`. Let me know if this is incorrect. |
| Comment by Robert Stam [ 07/Aug/23 ] |
|
Note: the test for "b != null" is not necessary and can be removed. |
| Comment by Robert Stam [ 07/Aug/23 ] |
|
Thank you for reporting this. I would like to investigate it. The summary says "DateTime.Year throws an exception" but your sample code does not use `Year` at all. Can you please clarify? Thanks. |
| Comment by PM Bot [ 02/Aug/23 ] |
|
Hi sasan.pasha@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon. |