我正在使用官方 MongoDB C# Drive v0.9.1.26831,但我想知道给定一个 POCO 类,是否有忽略某些属性的插入。
例如,我有以下类(class):
public class GroceryList
{
public string Name { get; set; }
public FacebookList Owner { get; set; }
public bool IsOwner { get; set; }
}
有没有办法让 IsOwner 在我插入 GroceryList 对象时不被插入? 基本上,我从数据库中获取对象,然后在应用层设置 IsOwner 属性,然后将其返回给 Controller ,然后 Controller 将对象映射到 View 模型。
希望我的问题有意义。谢谢!
最佳答案
看起来 [BsonIgnore] 属性完成了这项工作。
public class GroceryList : MongoEntity<ObjectId>
{
public FacebookList Owner { get; set; }
[BsonIgnore]
public bool IsOwner { get; set; }
}
关于c# - MongoDB C# 驱动程序 : Ignore Property on Insert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4892816/