Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2530

MongoDB C# driver enum mapping

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      I have Enum:

      {{}}

      public enum SomeType
      {
         TypeA,
         TypeB, 
         TypeC
      }

      {{}}

      but in MongoDB i would like this map to: type_a type_b type_c

      I'm using EnumRepresentationConvention(BsonType.String)

      I tried:

      {{}}

      public enum SomeType
      {
         [BsonElement("type_a")]
         TypeA,
         [BsonElement("type_b")]
         TypeB, 
         [BsonElement("type_c")]
         TypeC
      }

      {{}}

      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?

            Assignee:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Reporter:
            kurakmen@gmail.com Jakub Dropia
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: