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

IdPropertyConvention is not working when using other name that is not "_id".

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 0.7
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      IdPropertyConvention is not working when using other name that is not "_id".

      I copy the UnitTest from CSharp77Test below but change _id to _id2, run and see the result.

      In MongoDB (currently bug),

      {"_id" : ObjectId("xxxxxxxxxxxxxxxxxx"), "_id2" : ObjectId("yyyyyyyyyyyy")}

      Expected:

      {"_id" : ObjectId("xxxxxxxxxxxxxxxxxx") }

      // with out _id2

      private class Foo {
      public ObjectId _id2

      { get; set; }
      public string Name { get; set; }

      public string Summary

      { get; set; }

      }

      [Test]
      public void TestSave() {
      var server = MongoServer.Create();
      var database = server["onlinetests"];
      var collection = database.GetCollection<Foo>("csharp77");

      var conventions = new ConventionProfile()
      .SetIdPropertyConvention(new NamedIdPropertyConvention("_id2"));
      BsonClassMap.RegisterConventions(conventions, t => t == typeof(Foo));

      collection.RemoveAll();
      for (int i = 0; i < 10; i++) {
      var foo = new Foo {
      _id2 = ObjectId.Empty,
      Name = string.Format("Foo-

      {0}", i),
      Summary = string.Format("Summary for Foo-{0}

      ", i)
      };
      collection.Save(foo, SafeMode.True);
      var count = collection.Count();
      Assert.AreEqual(i + 1, count);
      }

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

              Created:
              Updated:
              Resolved: