-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.0
-
Component/s: Serialization
-
None
I have a class, Foo, that looks like the following.
public class Foo { public ObjectId Id { get; set; } public string A { get; set; } public string B { get; set; } public string C { get; set; } }
And I map the class as follows
BsonClassMap.RegisterClassMap<Foo>(cm => { cm.AutoMap(); cm.MapMember(c => c.A).SetOrder(3); cm.MapMember(c => c.B).SetOrder(2); cm.MapMember(c => c.C).SetOrder(1); });
I expect my document to look like the following
> db.foo.findOne() { "_id" : ObjectId("58407cb1a589ca66b0d0ac48"), "C" : "0", "B" : "2016", "A" : "Jan" }
But they actually look like this.
> db.foo.findOne() { "_id" : ObjectId("58407bf8a589ca8f5cedb77b"), "A" : "Jan", "B" : "2016", "C" : "0" }
In order to get the desired order, I have to do the following mapping, making AutoMap last.
BsonClassMap.RegisterClassMap<Foo>(cm => { cm.MapMember(c => c.A).SetOrder(3); cm.MapMember(c => c.B).SetOrder(2); cm.MapMember(c => c.C).SetOrder(1); cm.AutoMap(); });
These should either be independent of order or we need to be explicit that SetOrder needs to come first.