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 ManyToManyCustomizer(IModelExplicitDeclarationsHolder explicitDeclarationsHolder, PropertyPath propertyPath, ICustomizersHolder customizersHolder) { if (explicitDeclarationsHolder == null) { throw new ArgumentNullException("explicitDeclarationsHolder"); } explicitDeclarationsHolder.AddAsManyToManyItemRelation(propertyPath.LocalMember); this.propertyPath = propertyPath; this.customizersHolder = customizersHolder; }
public static void Merge(this IModelExplicitDeclarationsHolder destination, IModelExplicitDeclarationsHolder source) { if (destination == null || source == null) { return; } foreach (var o in source.RootEntities) { destination.AddAsRootEntity(o); } foreach (var o in source.Components) { destination.AddAsComponent(o); } foreach (var o in source.TablePerClassEntities) { destination.AddAsTablePerClassEntity(o); } foreach (var o in source.TablePerClassHierarchyEntities) { destination.AddAsTablePerClassHierarchyEntity(o); } foreach (var o in source.TablePerConcreteClassEntities) { destination.AddAsTablePerConcreteClassEntity(o); } foreach (var o in source.OneToOneRelations) { destination.AddAsOneToOneRelation(o); } foreach (var o in source.ManyToOneRelations) { destination.AddAsManyToOneRelation(o); } foreach (var o in source.KeyManyToManyRelations) { destination.AddAsManyToManyKeyRelation(o); } foreach (var o in source.ItemManyToManyRelations) { destination.AddAsManyToManyItemRelation(o); } foreach (var o in source.ManyToAnyRelations) { destination.AddAsManyToAnyRelation(o); } foreach (var o in source.OneToManyRelations) { destination.AddAsOneToManyRelation(o); } foreach (var o in source.Any) { destination.AddAsAny(o); } foreach (var o in source.Poids) { destination.AddAsPoid(o); } foreach (var o in source.ComposedIds) { destination.AddAsPartOfComposedId(o); } foreach (var o in source.VersionProperties) { destination.AddAsVersionProperty(o); } foreach (var o in source.NaturalIds) { destination.AddAsNaturalId(o); } foreach (var o in source.Sets) { destination.AddAsSet(o); } foreach (var o in source.Bags) { destination.AddAsBag(o); } foreach (var o in source.IdBags) { destination.AddAsIdBag(o); } foreach (var o in source.Lists) { destination.AddAsList(o); } foreach (var o in source.Arrays) { destination.AddAsArray(o); } foreach (var o in source.Dictionaries) { destination.AddAsMap(o); } foreach (var o in source.Properties) { destination.AddAsProperty(o); } foreach (var o in source.PersistentMembers) { destination.AddAsPersistentMember(o); } foreach (var o in source.SplitDefinitions) { destination.AddAsPropertySplit(o); } foreach (var dynamicComponent in source.DynamicComponents) { var template = source.GetDynamicComponentTemplate(dynamicComponent); destination.AddAsDynamicComponent(dynamicComponent, template); } }