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

Id property mapping issues when using camel-case convention and mapping-by-code approach

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.0.1
    • BSON

    Description

      I'm experiencing a strange issue where the driver is correctly mapping some class properties excepting the SomeClass.Id property when using CamelCaseElementNameConvention.

      The code is something like the following one:

                     var pack = new ConventionPack();
                                     pack.Add(new CamelCaseElementNameConvention());
       
                                     ConventionRegistry.Register(
                                       "SimsaConventions",
                                       pack, t => true);
      

      I've tried to add a BsonClassMap using m.AutoMap() and then trying to map the id property and setting an element name "id" to force it to work with no luck, while adding [BsonElement("id")] in the Id property workarounds the issue.

      BTW, I understand that the camel-case convention should be used during serialization and deserialization and it shouldn't produce a conflict.

      The exception thrown during serialization without using BsonElementAttribute is that "id" element name can't be found.

      Using Visual Studio's debugger watches I could find that member name is "Id" even after call .SetElementName("id"). BTW, I insist in that I understand that both camel-case convention and auto-mapping should work together. Am I wrong?

      Attachments

        Activity

          People

            Unassigned Unassigned
            mfidemraizer Matías Fidemraizer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: