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

BsonId attribute does not opt-in the member.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.8
    • Affects Version/s: 1.6
    • Component/s: None
    • Labels:

      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.

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            zaidmasud Zaid Masud
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: