示例#1
0
        public override void MapField(ICustomizersHolder customizerHolder,
                                      IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder,
                                      PropertyPath currentPropertyPath,
                                      MetaEntity entity,
                                      MetaField property)
        {
            var m2mProperty = property as ManyToManyMetaField;
            var refEntity   = _entityManager.GetEntity(m2mProperty.RefEntityName);
            var refProperty = refEntity.Fields[m2mProperty.MappedByFieldName];
            var joinTableThisSideFkColumn  = _nameConvention.EntityFieldToColumn(entity.Name.Split('.').Last() + "Id");
            var joinTableOtherSideFkColumn = _nameConvention.EntityFieldToColumn(refEntity.Name.Split('.').Last() + "Id");

            var bagMappingAction = new Action <IBagPropertiesMapper>(mapper => {
                mapper.Table(m2mProperty.JoinTable);
                mapper.Key(keyMapper => {
                    keyMapper.Column(joinTableThisSideFkColumn);
                    keyMapper.NotNullable(true);
                });
            });

            var m2mMappingAction = new Action <IManyToManyMapper>(mapper => {
                mapper.Class(refEntity.ClrType);
                mapper.Column(joinTableOtherSideFkColumn);
            });

            var next = new PropertyPath(currentPropertyPath, property.ClrPropertyInfo);

            customizerHolder.AddCustomizer(next, m2mMappingAction);
            customizerHolder.AddCustomizer(next, bagMappingAction);

            modelExplicitDeclarationsHolder.AddAsManyToManyItemRelation(property.ClrPropertyInfo);
            modelExplicitDeclarationsHolder.AddAsBag(property.ClrPropertyInfo);
        }
 public override void Apply(MetaField field)
 {
     field.DbName = _dbNameConvention.EntityFieldToColumn(field.Name);
 }