I need to define a composite key (_id) on an existing class (MyClass), which is composed of 2 class properties: Id & Version. Also, it has to be done via the BsonClassMap API (and not property attributes), since I cannot change the class code.
I tried something like this, but the second call to SetIdMember() just overrides the first call and doesn't add it to the key:
BsonClassMap.RegisterClassMap<MyClass>(cm =>
{
cm.AutoMap();
cm.SetIgnoreExtraElements(true);
cm.SetIdMember(cm.GetMemberMap(t => t.Id));
cm.SetIdMember(cm.GetMemberMap(t => t.Version)); // after this line, the ID seems to be just Version and not Id+Version
});