MongoDB C# Driver: Ignore Property on Insert

前端 未结 5 1651
余生分开走
余生分开走 2021-02-03 18:48

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.

For ex

5条回答
  •  借酒劲吻你
    2021-02-03 19:36

    Also you can make IsOwner Nullable and add [BsonIgnoreExtraElements] to the whole class:

    [BsonIgnoreExtraElements]
    public class GroceryList : MongoEntity
    {
        public FacebookList Owner { get; set; }
        public bool? IsOwner { get; set; }
    }
    

    A property with null value will be ignored during serialization. But I think [BsonIgnore] will be better for your case.

提交回复
热议问题