I have a base class similar to:
public class Entity
{
public virtual object Id { get; set; }
}
And concrete classes override the property with more specific types, using C#'s covariant return type feature:
public class User : Entity
{
public override string Id { get; set; }
}
(This is a simplification of my situation, I'm not asking for a better model but only how to persist it)
Now my problem is that the Mongo BSON serializer thinks these are two separate properties, and it throws an exception because there are two properties that map to the same element.
How can I persist such a model (where properties are overridden with more specific types, assuming the types of the properties are serializable)?