[CSHARP-4524] Handle projections using constructors for classes that use public fields instead of public properties Created: 13/Feb/23 Updated: 28/Oct/23 Resolved: 28/Feb/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 2.19.0 |
| Fix Version/s: | 2.19.1 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Alkis Tsapanidis | Assignee: | Robert Stam |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Bug | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||||||
| Issue Links: |
|
||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||
| Documentation Changes: | Not Needed | ||||||||||||||||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
||||||||||||||||
| Description |
| Comments |
| Comment by Githook User [ 24/Mar/23 ] |
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: |
| Comment by Githook User [ 28/Feb/23 ] |
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: |
| Comment by Robert Stam [ 14/Feb/23 ] |
|
Thanks for reporting this issue. Note that LINQ2 would sometimes split a projection into two parts: the first executed on the server and the second on the client. LINQ3 no longer does that because we consider that to have been a bad idea as it hides potential performance issues. If you want to execute part of your projection client side you should do so explicitly. However, as of server version 4.4 the server now supports the same projections in Find as in the aggregate $project stage, so Find can still use many projections as long as they can be translated to a $project projection. In your case the projection is simple enough that it could be translated to a $project projection, but the LINQ3 code that does that neglected to handle classes with public fields instead of public properties. I have implemented a fix that allows your sample to run using LINQ3, as long as you are using server 4.4 or newer. |
| Comment by Alkis Tsapanidis [ 13/Feb/23 ] |
|
The only workaround I have found is to project to some anonymous type and then construct my own type from it afterwards, which is not really acceptable either in terms of the boilerplate produced, nor performance (extra allocations every time). |