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

BsonId attribute does not opt-in the member.

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 1.8
    • 1.6
    • None

    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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: