如何将自定义名称作为键和值属性名称赋予C#MongoDB驱动程序DictionaryRepresantation.ArrayOfDocuments

时间:2018-11-05 10:26:52

标签: c# mongodb

我需要使用BsonSerializer序列化一个具有Dictionary类型属性的C#类。

我使用DictionaryRepresentation.ArrayOfDocuments,但是它会自动为属性名称提供“ k”和“ v”并生成如下内容:

Field : [ 
   {"k" : "100","v" : "5"},
   {"k" : "200","v" : "2"}
]

但是我想生成这个:

Field : [ 
   {"Point" : "100","Order" : "5"},
   {"Point" : "200","Order" : "2"}
]

如何为属性名称指定“点”和“订单”名称? 感谢您的帮助

编辑:这是我的课:

[BsonIgnoreExtraElements]
[Upsertable(typeof(Player))]
public class Player     {
    /// <summary>
    /// Gets or Sets PlayerId property of <see cref="Player"/> object.
    /// </summary>
    [BsonId]
    [UpsertableId]
    public int PlayerId { get; set; }

    /// <summary>
    /// Gets or Sets PlayerName property of <see cref="Player"/> object.
    /// </summary>
    public string PlayerName{ get; set; }

    /// <summary>
    /// Gets or Sets PointOrders property of <see cref="Player"/> object
    /// </summary>
    [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)]
    public Dictionary<int, int> PointOrders{ get; set; }

}

我想如上所述序列化PointOrders属性。

0 个答案:

没有答案