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

BsonId attribute does not opt-in the member.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 1.6
    • Fix Version/s: 1.8
    • Component/s: None
    • Labels:

      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

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: