I am using the Mongodb official driver and I want to set by default the naming of the elements to lower case to avoid code like this:
public class Localization
{
[BsonId(IdGenerator = typeof(ObjectIdGenerator))]
public int Id { get; set; }
[BsonRequired]
[BsonElement("country")]
public string Country { get; set; }
In this sample I want that by default the element name be "country" not "Country" aka lower case. Is it possible?
Thanks
A small update since the BsonClassMap.RegisterConventions is marked as obsolete
var camelCaseConventionPack = new ConventionPack { new CamelCaseElementNameConvention() };
ConventionRegistry.Register("CamelCase", camelCaseConventionPack, type => true);
var conventions = new ConventionProfile();
conventions.SetElementNameConvention(new CamelCaseElementNameConvention());
BsonClassMap.RegisterConventions(conventions, t => true);
MongoDB CSharp Driver Serialization Tutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With