MongoDB C#驱动程序:忽略插入时的属性 [英] MongoDB C# Driver: Ignore Property on Insert
问题描述
我使用的是MongoDB C#官方驱动器v0.9.1.26831,但我想知道是否有POCO类,无论如何都将忽略某些属性.
I am using the Official MongoDB C# Drive v0.9.1.26831, but I was wondering given a POCO class, is there anyway to ignore certain properties from getting inserted.
例如,我有以下课程:
public class GroceryList
{
public string Name { get; set; }
public FacebookList Owner { get; set; }
public bool IsOwner { get; set; }
}
有没有办法让我插入GroceryList对象时不会插入 IsOwner ? 基本上,我从数据库中获取对象,然后在应用程序层中设置IsOwner属性,然后将其返回给控制器,然后该控制器将对象映射到视图模型.
Is there a way, for the IsOwner to not get inserted when I insert a GroceryList object? Basically, I fetch the object from the database then set the IsOwner property in the app layer and then return it back to the controller, which than maps the object to a view model.
希望我的问题有道理.谢谢!
Hope my question makes sense. thanks!
推荐答案
看起来[BsonIgnore]属性完成了这项工作.
It looks like the [BsonIgnore] attribute did the job.
public class GroceryList : MongoEntity<ObjectId>
{
public FacebookList Owner { get; set; }
[BsonIgnore]
public bool IsOwner { get; set; }
}
这篇关于MongoDB C#驱动程序:忽略插入时的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!