private static bool TryGetWithRelationship( AssociationSetMapping colocatedAssociationSetMap, EntitySetBase thisExtent, MemberPath sRootNode, ref List <SlotInfo> foreignKeySlots, out WithRelationship withRelationship) { withRelationship = (WithRelationship)null; EndPropertyMapping fromAssocitionMap = LeafCellTreeNode.GetForeignKeyEndMapFromAssocitionMap(colocatedAssociationSetMap); if (fromAssocitionMap == null || fromAssocitionMap.AssociationEnd.RelationshipMultiplicity == RelationshipMultiplicity.Many) { return(false); } AssociationEndMember associationEnd = fromAssocitionMap.AssociationEnd; AssociationEndMember otherAssociationEnd = MetadataHelper.GetOtherAssociationEnd(associationEnd); EntityType elementType1 = (EntityType)((RefType)associationEnd.TypeUsage.EdmType).ElementType; EntityType elementType2 = (EntityType)((RefType)otherAssociationEnd.TypeUsage.EdmType).ElementType; AssociationSet set = (AssociationSet)colocatedAssociationSetMap.Set; MemberPath prefix = new MemberPath((EntitySetBase)set, (EdmMember)associationEnd); IEnumerable <ScalarPropertyMapping> source = fromAssocitionMap.PropertyMappings.Cast <ScalarPropertyMapping>(); List <MemberPath> memberPathList = new List <MemberPath>(); foreach (EdmProperty keyMember in elementType1.KeyMembers) { EdmProperty edmProperty = keyMember; ScalarPropertyMapping scalarPropertyMapping = source.Where <ScalarPropertyMapping>((Func <ScalarPropertyMapping, bool>)(propMap => propMap.Property.Equals((object)edmProperty))).First <ScalarPropertyMapping>(); MemberProjectedSlot memberProjectedSlot = new MemberProjectedSlot(new MemberPath(sRootNode, (EdmMember)scalarPropertyMapping.Column)); MemberPath outputMember = new MemberPath(prefix, (EdmMember)edmProperty); memberPathList.Add(outputMember); foreignKeySlots.Add(new SlotInfo(true, true, (ProjectedSlot)memberProjectedSlot, outputMember)); } if (!thisExtent.ElementType.IsAssignableFrom((EdmType)elementType2)) { return(false); } withRelationship = new WithRelationship(set, otherAssociationEnd, elementType2, associationEnd, elementType1, (IEnumerable <MemberPath>)memberPathList); return(true); }
private void WritePropertyMapping(ScalarPropertyMapping scalarPropertyMapping) { DebugCheck.NotNull(scalarPropertyMapping); WriteScalarPropertyElement(scalarPropertyMapping.Property.Name, scalarPropertyMapping.Column.Name); }
private static IEnumerable <TableDefinition> GetTableDefinitions(DbModelPlus model, string strName) { //get our entity type SchemaEntityType setEntityType = model.ConceptualModel.Index_EntityTypes_Name[strName]; //create our update entity TableDefinition ueEntity = new TableDefinition(); //create our return list and add our definition List <TableDefinition> lsTableDefinitions = new List <TableDefinition>(); //if we have mapping data, leverage it if (setEntityType.EntityTypeMapping != null) { lsTableDefinitions.Add(ueEntity); ueEntity.Schema = setEntityType.EntityTypeMapping.MappingFragment.StoreEntitySet.Schema; ueEntity.Table = setEntityType.EntityTypeMapping.MappingFragment.StoreEntitySet.Table; //map our keys for this model List <ScalarPropertyMapping> lsKeys = new List <ScalarPropertyMapping>(); foreach (PropertyRefElement propertyKey in setEntityType.EntityTypeMapping.MappingFragment.StoreEntitySet.EntityType.Key.PropertyRefs) { ScalarPropertyMapping mappingProperty = setEntityType.EntityTypeMapping.MappingFragment.ScalarProperties.Find(x => x.Name == propertyKey.Name); if (mappingProperty == null) { throw new Exception(string.Format(ExceptionMessage.BatchOperations_PropertyNotFound, propertyKey.Name)); } lsKeys.Add(mappingProperty); } ueEntity.Keys = lsKeys; //clone our list of properties ueEntity.Properties = setEntityType.EntityTypeMapping.MappingFragment.ScalarProperties.ToList(); //if there's no base type, stop here if (string.IsNullOrEmpty(setEntityType.BaseType)) { return(lsTableDefinitions); } } //stop here if there's no base type if (string.IsNullOrEmpty(setEntityType.BaseType)) { return(lsTableDefinitions); } //strip the alias bit string strBaseType = setEntityType.BaseType.Replace(model.ConceptualModel.Alias + ".", ""); //get the columns for our base class IEnumerable <TableDefinition> lsBaseTableDefinitions = GetTableDefinitions(model, strBaseType); //increment the order of the base column entities by one foreach (TableDefinition ueBaseEntity in lsBaseTableDefinitions) { ueBaseEntity.Order += 1; lsTableDefinitions.Add(ueBaseEntity); } return(lsTableDefinitions); }
private void WritePropertyMapping(ScalarPropertyMapping scalarPropertyMapping) { this.WriteScalarPropertyElement(scalarPropertyMapping.Property.Name, scalarPropertyMapping.Column.Name); }