Hi All,
I am facing issue related to element name in mongo collection. My class declaration is
public class Template : MongoModel, ITemplate
{
[BsonRequired]
[BsonElement("Name")]
public string Name { get; set; }
[BsonRequired]
[BsonElement("Key")]
public string Key { get; set; }
[BsonElement("Desc")]
public string Description { get; set; }
[BsonRequired]
[BsonElement("PS")]
public long PageSize { get; set; }
[BsonElement("Gps")]
public List<FieldGroup> Groups { get; set; }
[BsonElement("EGUID")]
public string EntityGuid { get; set; }
[BsonDefaultValue(false)]
[BsonElement("STemp")]
public bool IsSystemTemplate { get; set; }
[BsonElement("CTemp")]
public bool HasCustomTemplate { get; set; }
[BsonElement("CCmds")]
public List<ITemplateCommand> CollectionCommands { get; set; }
[BsonElement("ECmds")]
public List<ITemplateCommand> EditorCommand { get; set; }
}
As you can see i have assigned BsonElement to all properties. But when I save the document i am seeing property names, instead it should take values from BsonElement attribute. For some strange reason it is working for embedded document but not main document.
I wrote a extension method to register the call mapping and calling that from Start of application.
BsonClassMap.RegisterClassMap<Template>(opt =>
{
opt.AutoMap();
});
I am using Mongodb 4.2.1 community and c# driver version is 2.10.4
I want to know why [BsonElement] attribute is not honored.