When creating class maps, you map each member at the level at which it is declared, so you need to map MiscellaneousDataBase and MiscellaneousData separately.
Below is a code example showing how to map each class separately (I added the X property to the subclass so that there is something to display at this level).
Using these classes:
public abstract class MiscellaneousDataBase { public abstract string Key { get; set; } } public class MiscellaneousData : MiscellaneousDataBase { public override string Key { get; set; } public int X { get; set; } }
try matching them like this:
BsonClassMap.RegisterClassMap<MiscellaneousDataBase>(cm => { cm.AutoMap(); cm.SetIdMember(cm.GetMemberMap(c => c.Key)); cm.IdMemberMap.SetIdGenerator(StringObjectIdGenerator.Instance); }); BsonClassMap.RegisterClassMap<MiscellaneousData>(cm => { cm.AutoMap(); cm.GetMemberMap(c => cX).SetElementName("x"); });
source share