Inheritance and serialization objects from mongoDB

First of all thank you for the help.

How it is possible to handle when documents are in a class model that inherits a context.

My intention was to manage a single integration

If I include documents in this way.

"public void Insertar(Frutas Objeto)

var cliente = new MongoClient(ConnectionURI);




By invoking this way this service works well, I use apple that has heart and orange that has exocarp…

Manzana Frut1 = new();

Frut1.CoreSize =50mm;


Naranja Frut2 = new();

Frut2. exocarpoSize =3mm;


All good with insertion

And to get use something like this

public Frutas? Get(BsonDocument filtro)
Frutas Resultado;
var cliente = new MongoClient(ConnectionURI);
Resultado = cliente.GetDatabase(this.DatabaseName).
catch (Exception ex)
Resultado = default(Frutas);

return Resultado

I create an apple

Manzana frut1 = new();
Frutas frutGeneric = new();

For some reason I must use the generic fruit, which is possible.
frutGeneric = frut1;

If I consult the apple, everything works fine until I come across:


Element ‘CoreSize’ does not match any field or property of class DefineSemilla.Frutas.


And it makes sense because Frutas doesn’t have all the properties of the apple

“Dictionary<string, object> filtroTrx = new()
{” CoreSize “, “50mm”},
BsonDocument Buscar = new(filtroTrx);
frutGeneric = Get(Buscar);”

How could I avoid this error? because the destination has the property and the property is in mongoDB, only when serializing considers only the properties of fruits, throwing an error when reading content from the database.