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
You can customize the class map for the class that contains the enum and specify that the member be represented by a string. This will handle both the serialization and deserialization of the enum.
if (!MongoDB.Bson.Serialization.BsonClassMap.IsClassMapRegistered(typeof(Person)))
{
MongoDB.Bson.Serialization.BsonClassMap.RegisterClassMap(cm =>
{
cm.AutoMap();
cm.GetMemberMap(c => c.Gender).SetRepresentation(BsonType.String);
});
}
I am still looking for a way to specify that enums be globally represented as strings, but this is the method that I am currently using.