Storing Enums as strings in MongoDB

后端 未结 9 1280
盖世英雄少女心
盖世英雄少女心 2020-12-08 03:50

Is there a way to store Enums as string names rather than ordinal values?

Example:

Imagine I\'ve got this enum:

public enum Gender
{
    Fema         


        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 04:19

    Use MemberSerializationOptionsConvention to define a convention on how an enum will be saved.

    new MemberSerializationOptionsConvention(typeof(Gender), new RepresentationSerializationOptions(BsonType.String))
    

提交回复
热议问题