[EF-71] Mapping of ObjectIds to strings in entities Created: 06/Nov/23 Updated: 14/Nov/23 |
|
| Status: | Backlog |
| Project: | Entity Framework |
| Component/s: | None |
| Affects Version/s: | Public Preview 1 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Critical - P2 |
| Reporter: | Markus Wildgruber | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 4 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
When mapping MongoDB documents to C# classes, having string properties in the classes simplifies the handling of ObjectIds very much. In the existing driver for C#, this can be done by applying an [BsonRepresentation(BsonType.ObjectId)]-attribute to the property (also works if the property is an array or enumeration). However, this had no effect for the EF provider. Also, adding a conversion when defining the model did not help, but led to an exception: modelBuilder.Entity<Movie>() Exception: This format is neither recognizable as an ObjectId by a human, nor can it be used as URL parameter in an API easily. So one would have to create a custom serializer for the API anyway; better yet if the EF provider supported the mapping in the same way as the existing driver for C#. Additional side info: creating an EDM-model for OData based upon the class also had difficulties with the id being an ObjectId; I expect this to handle a string without a problem. (sorry, I'm not a MongoDB employee so I had to create a bug issue for this. From my point of view, it's more of an improvement - but an important one) |
| Comments |
| Comment by Esha Bhargava [ 06/Nov/23 ] |
|
m.wildgruber@sevantage.de Thank you for your suggestion. We'll consider it for a future version. |