[CSHARP-1350] Id property mapping issues when using camel-case convention and mapping-by-code approach Created: 17/Jul/15  Updated: 28/May/20  Resolved: 04/Apr/16

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Matías Fidemraizer Assignee: Unassigned
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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?



 Comments   
Comment by Craig Wilson [ 17/Jul/15 ]

Hi Matias,

First, I think the "id" problem you are hitting is this: CSHARP-1080. I'm sure you are aware, but collection-level documents are required to have an _id field which is why we see your "id" field and use it as "_id". Certainly, this isn't always true, but very few people want both an "_id" and an "id".

Second, in order for your conventions to apply, you must call AutoMap. AutoMap is the call that actually runs the conventions.

Craig

Comment by Matías Fidemraizer [ 17/Jul/15 ]

Well, in fact I'm experiencing the same issue with all properties. Once I use the camel-case convention, I get an excepting which says that serializer couldn't find some property and it states it tried to deserialize a pascal-cased element name...

Generated at Wed Feb 07 21:39:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.