-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
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
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-
Summary = string.Format("Summary for Foo-{0}
", i)
};
collection.Save(foo, SafeMode.True);
var count = collection.Count();
Assert.AreEqual(i + 1, count);
}