我有以下数据模型:(在C#中使用MongoDB)
public class aClass
{
public virtual string Content { get; set; }
}
public class aClassDao
{
public override string Content { get; set; }
}
public class MongoDbContext
{
public IMongoDatabase Database { get; }
public IMongoCollection<aClassDao> Classes=> Database.GetCollection<aClassDao>("Classes");
public MongoDbContext()
{
// some connection logic
}
}
当我启动应用程序时,我得到以下错误:
MongoDB.Bson.BsonSerializationException: The property 'Content' of type 'aClassDao' cannot use element name
'Content' because it is already being used by property 'Content' of type 'aClass'.
型
1条答案
按热度按时间kt06eoxx1#
我不认为有一个很好的方法基于这篇文章https://www.mongodb.com/community/forums/t/bsonserializationexception-when-inheriting-from-domain-object-class/159341
最后,我用自动Map器解决方案,它更直接。
基本上只需要创建一个新的对象,匹配的集合的类型