[CSHARP-85] IdPropertyConvention is not working when using other name that is not "_id". Created: 25/Oct/10  Updated: 02/Apr/15  Resolved: 25/Oct/10

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 0.7

Type: Bug Priority: Major - P3
Reporter: Payut M Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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);
}



 Comments   
Comment by Robert Stam [ 25/Oct/10 ]

Fixed in master.

Generated at Wed Feb 07 21:35:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.