[CSHARP-464] When Calling SetIdMember, ElementName Of Map Is Not Used Created: 03/May/12  Updated: 19/Oct/16  Resolved: 03/May/12

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

Type: Bug Priority: Major - P3
Reporter: Tim Scott Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-465 Can't Change Id Element Name To "Id" Closed

 Description   

I have like this:

BsonClassMap.RegisterClassMap<LoadPlan>(x => {
x.AutoMap();
var idMap = x.GetMemberMap(c => c.Id).SetElementName("Id");
x.SetIdMember(idMap);
}):

At the end of the closure x.IdMemberMap.ElementName is "_id". I expect it to be "Id".



 Comments   
Comment by Tim Scott [ 03/May/12 ]

I updated to 1.4, and the issue has been fixed. The impetus for this mapping was I was getting duplicate key error upon calling Save on a previously inserted document. I had read in a forum post that the document needs an key called "Id" and not "_id", and this mapping was an attempt to do that. In any case, the issue is fixed in the latest version without a need to change the element name.

Comment by Craig Wilson [ 03/May/12 ]

Every document in MongoDB contains an element called "_id". It is the identifier field for a document. In the case of a BsonClassMap, the IdMember will always serialize with the element name of "_id" regardless of whether or not you change the element name.

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