public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap)
        {
            var entityType = definition.EntityType;
            var properties = entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            foreach (var property in properties)
            {
                //Unmap fields with the "NotMappedAttribute"
                var notMappedAttribute = property.GetCustomAttribute <NotMappedAttribute>();
                if (notMappedAttribute != null)
                {
                    classMap.UnmapProperty(property.Name);
                    continue;
                }

                //Remap fields with the "ColumnAttribute"
                var columnAttribute = property.GetCustomAttribute <ColumnAttribute>();
                if (columnAttribute != null)
                {
                    var mappedName = columnAttribute.Name;
                    var memberMap  = classMap.GetMemberMap(property.Name);
                    memberMap?.SetElementName(mappedName);
                }
            }
        }
        public override void Map(BsonClassMap <MyClass> cm)
        {
            cm.AutoMap();

            //every doc has to have an id
            cm.MapIdField(x => x.Id).SetIdGenerator(new StringObjectIdGenerator());

            cm.MapProperty(x => x.SomeProperty)
            .SetElementName("sp");     // will set the element name to "sp" in the stored documents

            //unmap the property.. now we won't save it
            cm.UnmapProperty(x => x.SomeOtherProperty);
        }
Exemplo n.º 3
0
 protected override void MapEntity(BsonClassMap <Vehicle> cm)
 {
     cm.MapIdField(x => x.Id).SetIdGenerator(this.IdGenerator);
     cm.UnmapProperty(x => x.DateOfProduction);
     cm.AutoMap();
 }
Exemplo n.º 4
0
 protected override void ConfigureTableMappings(BsonClassMap <Company> bsonClassMap)
 {
     bsonClassMap.UnmapProperty(e => e.StateName);
 }