[CSHARP-2530] MongoDB C# driver enum mapping Created: 25/Feb/19 Updated: 19/Jun/19 Resolved: 07/May/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Jakub Dropia | Assignee: | Wan Bachtiar |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I have Enum: {{}}
{{}} but in MongoDB i would like this map to: type_a type_b type_c I'm using EnumRepresentationConvention(BsonType.String) I tried: {{}}
{{}} but this doesn't work. Im getting exception: Requested value 'type_a' was not found. Is anyone know how can achieve such mapping in MongoDb C# driver? |
| Comments |
| Comment by Wan Bachtiar [ 14/Jun/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Jakub, This is out of the design scope for the driver. You could try using reflection with a generic custom serialiser. Regards, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jakub Dropia [ 24/May/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi, thanks for reply! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Wan Bachtiar [ 19/Mar/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Hi Jakub,
You can write a custom class deserialiser/serializer as below:
Then you need to register it:
Please note that the CSHARP project is for reporting bugs or feature suggestions for the MongoDB .NET/C# driver. If you have any follow-up questions on the use of the driver, please post a question on mongodb-user group with relevant the information. Regards, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jakub Dropia [ 18/Mar/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Any thoughts? |