This borders on a bug in the C # driver. It turns out that IdMemberMap is not defined until the class map is frozen for reasons related to class hierarchies in which the Identifier can be defined in the base class. One way around this is:
BsonClassMap.RegisterClassMap<Person>(cm => { cm.AutoMap(); cm.Freeze(); cm.IdMemberMap.SetRepresentation(BsonType.ObjectId); });
Another workaround is to use GetMemberMap instead of IdMemberMap:
BsonClassMap.RegisterClassMap<Person>(cm => { cm.AutoMap(); cm.GetMemberMap(c => c.Id).SetRepresentation(BsonType.ObjectId); });
source share