private MiddleComponentData addIndex(XElement middleEntityXml, QueryGeneratorBuilder queryGeneratorBuilder) { var indexedValue = _propertyValue as IndexedCollection; if (indexedValue != null) { var idMatch = false; Property referencedProperty = null; PersistentClass refPc = null; if (_referencedEntityName != null) { refPc = _mainGenerator.Cfg.GetClassMapping(_referencedEntityName); } if (refPc != null) { idMatch = MappingTools.SameColumns(refPc.IdentifierProperty.ColumnIterator, indexedValue.Index.ColumnIterator); foreach (var propertyRef in refPc.PropertyIterator) { if (MappingTools.SameColumns(propertyRef.ColumnIterator, indexedValue.Index.ColumnIterator)) { referencedProperty = propertyRef; break; } } } if (!idMatch && referencedProperty == null) { return(addValueToMiddleTable(indexedValue.Index, middleEntityXml, queryGeneratorBuilder, "mapkey", null)); } var currentIndex = queryGeneratorBuilder?.CurrentIndex ?? 0; if (idMatch) { // The key of the map is the id of the entity. var referencedIdMapping = _mainGenerator.EntitiesConfigurations[_referencedEntityName].IdMappingData; return(new MiddleComponentData(new MiddleMapKeyIdComponentMapper(_mainGenerator.VerEntCfg, referencedIdMapping.IdMapper), currentIndex)); } if (indexedValue is Map) { // The key of the map is a property of the entity. return(new MiddleComponentData(new MiddleMapKeyPropertyComponentMapper(referencedProperty.Name, referencedProperty.PropertyAccessorName), currentIndex)); } //bidirectional list // The key of the map is a property of the entity. return(new MiddleComponentData(new MiddleStraightComponentMapper(referencedProperty.Name), currentIndex)); } // No index - creating a dummy mapper. return(new MiddleComponentData(new MiddleDummyComponentMapper(), 0)); }
private static void mightAddIndexToAttribute(AuditMappedByAttribute auditMappedByAttribute, Mapping.Collection collectionValue, IEnumerable <Property> referencedProperties) { //check index value if (!(collectionValue is IndexedCollection indexValue)) { return; } foreach (var referencedProperty in referencedProperties) { if (MappingTools.SameColumns(referencedProperty.ColumnIterator, indexValue.Index.ColumnIterator) && !referencedProperty.IsUpdateable && !referencedProperty.IsInsertable) { auditMappedByAttribute.PositionMappedBy = referencedProperty.Name; } } }
private static bool isRelation(Mapping.Collection collection, Property potentialBackRefProperty) { return(MappingTools.SameColumns(potentialBackRefProperty.ColumnIterator, collection.Key.ColumnIterator) && isEqualOrDerived(collection.Owner.MappedClass, potentialBackRefProperty.Type.ReturnedClass)); }
private static bool isRelation(Mapping.Collection collectionValue, Property referencedProperty) { return(MappingTools.SameColumns(referencedProperty.ColumnIterator, collectionValue.Key.ColumnIterator) && collectionValue.Owner.MappedClass.IsAssignableFrom(referencedProperty.Type.ReturnedClass)); }