MongoDB C# Driver: Ignore Property on Insert

前端 未结 5 1649
余生分开走
余生分开走 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:15

    Alternatively, if you don't want to use the attribute for some reason (e. g. in case you don't want to bring an extra dependency to MongoDB.Bson to your DTO), you can do the following:

    BsonClassMap.RegisterClassMap(cm =>
    {
      cm.AutoMap();
      cm.UnmapMember(m => m.IsOwner);
    });
    

提交回复
热议问题