Do not insert field if null or empty

后端 未结 2 1035
暗喜
暗喜 2021-01-04 23:51

I have a C# class with some fields and some of them are null. Those that are null I do not want to be inserted into db with null value. I do not want them inserted into db a

2条回答
  •  不知归路
    2021-01-05 00:28

    Using the aptly named [BsonIgnoreIfNull] attribute:

    class User
    {
        public string FirstName;
        public string LastName;
        [BsonIgnoreIfNull]
        public string MidName;
    }
    

提交回复
热议问题