[CSHARP-4311] LINQ translation bug when document class derives from Dictionary<string, object> Created: 07/Sep/22 Updated: 27/Oct/23 Resolved: 27/Sep/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Unknown |
| Reporter: | Mo B. | Assignee: | James Kovacs |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | LINQ | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
| Comments |
| Comment by PM Bot [ 27/Sep/22 ] | |
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information. | |
| Comment by James Kovacs [ 12/Sep/22 ] | |
|
Hi, Mo, Please see my comment on As to why you get no results back from the query in LINQ3, the reason lies in how we serialize collection classes. When serializing collections, the expectation is that the collection is a list of values or name-value pairs. We do not expect serialization metadata in the form of BSON attributes. Thus [BsonElement("displayname")] is never considered during the serialization and the resulting query is:
You will notice that the query is on DisplayName and not displayname. These queries would work if your properties matched your database fields exactly (including casing). We still do not recommend the strongly-typed property bag approach, but you could make it work by any of the following means:
Please let us know if you have any additional questions. Sincerely, | |
| Comment by Boris Dogadov [ 09/Sep/22 ] | |
|
Thanks mywyb2@gmail.com for your report. Currently custom properties in Dictionary based types are not supported by standards serializers. So the mentioned code would not be supported. One option would be not using Dictionary bases types, and storing the additional data via BsonExtraElements: https://mongodb.github.io/mongo-csharp-driver/2.17/reference/bson/mapping/#supporting-extra-elements |