【问题标题】:Exclude Fields while saving document in mongodb in c#在 c# 中的 mongodb 中保存文档时排除字段
【发布时间】:2014-07-30 15:52:14
【问题描述】:

在使用 c# 将文档保存在 mongodb 中时,有什么方法可以排除字段? 例如我的班级是

class student
{
int rollnol;
string name;
string fees;
}

我想要的是,当我做 collection.Save(studentobject) 它不应该保存费用字段。

(我在 asp.net MVC 中使用它,所以任何使用注释的东西也可以工作)

【问题讨论】:

    标签: c# .net mongodb database nosql


    【解决方案1】:

    在序列化过程中使用 BsonIgnore 属性忽略元素http://api.mongodb.org/csharp/1.1/html/0b6cf485-682b-cbdf-25b4-b28401824c78.htm

    class student
    {
       int rollnol;
       string name;
    
       [BsonIgnore]
       string fees;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-03
      • 2016-02-15
      • 2021-11-13
      • 2023-03-24
      • 1970-01-01
      • 2020-11-21
      • 2015-07-30
      相关资源
      最近更新 更多