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

Generate ObjectId to wrong property when BsonId property is in the parent class

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Moved from: http://github.com/mongodb/mongo-csharp-driver/issues#issue/5

      Hi,

      I think this is not the correct result. Please see the following code:

      public class BaseModel
      { [BsonId] public ObjectId Id

      { get; set; } }

      public class User : BaseModel
      { public ObjectId FriendId { get; set; }

      }

      [TestFixture] public class Test
      { [Test] public void New()

      { ... // create collections var model = new User(); collection.Save(model); }

      }

      The result in mongodb is:

      db.user.find()

      { "FriendId" : ObjectId("xxxxxxxxxxxxxxxxxxxxxxx"), "_id" : ObjectId("0000000000000000000") }

      [I modified above code from my real code so the result might not be the same order but the point is in my result, new object id is assigned to wrong property]

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: