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

Derived classes can't put timestamp in second position for server to automatically fill in the value

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.7
    • Component/s: None
    • None

      If a document being saved to the server has an _id field in the first position and a zero valued BsonTimestamp (name doesn't matter) in the second position then the server fills in the value of the timestamp field automatically.

      But when using polymorphism with the C# driver this doesn't work for derived classes.

      Given the following classes:

      public class C
      {
          public int Id;
          public BsonTimestamp Timestamp;
      }
      
      public class D : C
      {
          public int X;
      }
      

      when an instance of D is serialized (assuming the nominal type is C) the result is:

      { _id : 1, _t : "D", Timestamp : { $timestamp : NumberLong(0) }, X : 1 }
      

      but since the driver inserted the _t discriminator field in the second position the server no longer sees the Timestamp field and doesn't fill the value in for you.

      The driver always puts the _t field in the second position so it doesn't have to scan too much of the document to find it, but in this case it should put it in the third position so the server can see the Timestamp in the second position.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: