[CSHARP-569] BsonId attribute does not opt-in the member. Created: 14/Sep/12  Updated: 20/Mar/14  Resolved: 01/Jan/13

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

Type: Bug Priority: Minor - P4
Reporter: Zaid Masud Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: C#, driver, insert
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on CSHARP-584 Improve the design of the convention ... Closed

 Description   

The ID field on an object is supposed to be populated after an Insert; however this does not work when the id field is private.

In particular, the following unit test fails:

public class PrivateIdField
{
    [BsonId]
    private ObjectId _id;
 
    public ObjectId Id { get { return _id; } }
}
 
[Test]
public void TestPrivateIdPopulation()
{
    var privateIdField = new PrivateIdField();
 
    _collection.Insert(privateIdField);
 
    Assert.AreNotEqual(privateIdField.Id, default(ObjectId));
}

I saw this example in Robert's stack overflow answer here.



 Comments   
Comment by Craig Wilson [ 01/Jan/13 ]

This has been resolved with the implementation of CSHARP-584.

Comment by Craig Wilson [ 14/Sep/12 ]

This looks like a bug in that we aren't picking up the [BsonId] attribute on the private field and therefore not picking up the private field either. For now, you could add a [BsonElement] attribute to it or include it using the fluent configuration api. Alternatively, you can create a custom IMemberFinderConvention or a custom IIdMemberFinderConvention to include this guy into the mix.

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