public static IPersistentTypeHasAssociations CreatePersistentTypesAssociation(ModelElement sourceElement, ModelElement targetElement, IAssociationInfo sourceInfo, IAssociationInfo targetInfo, string associationName, bool createPropertyEnd1, bool createPropertyEnd2) { PersistentType sourceEntity = (PersistentType)sourceElement; PersistentType targetEntity = (PersistentType)targetElement; PersistentTypeHasAssociations typeAssociations = new PersistentTypeHasAssociations(sourceEntity, targetEntity); typeAssociations.End1.Multiplicity = sourceInfo.Multiplicity; typeAssociations.End1.OnOwnerRemove = sourceInfo.OnOwnerRemove; typeAssociations.End1.OnTargetRemove = sourceInfo.OnTargetRemove; typeAssociations.End1.UseAssociationAttribute = sourceInfo.UseAssociationAttribute; // association End2 values typeAssociations.End2.Multiplicity = targetInfo.Multiplicity; typeAssociations.End2.OnOwnerRemove = targetInfo.OnOwnerRemove; typeAssociations.End2.OnTargetRemove = targetInfo.OnTargetRemove; typeAssociations.End2.UseAssociationAttribute = targetInfo.UseAssociationAttribute; typeAssociations.Name = associationName; NavigationProperty sourceNavigationProperty = createPropertyEnd1 ? new NavigationProperty(sourceElement.Partition) : null; //bool isToSelfLookup = sourceInfo == targetInfo; //NavigationProperty targetNavigationProperty = isToSelfLookup ? null : new NavigationProperty(targetElement.Partition); NavigationProperty targetNavigationProperty = null; //if (!isToSelfLookup || !createPropertyEnd1) if (createPropertyEnd2) { targetNavigationProperty = new NavigationProperty(targetElement.Partition); } if (sourceNavigationProperty != null) { sourceNavigationProperty.PersistentTypeOfNavigationProperty = sourceEntity; sourceNavigationProperty.Name = sourceInfo.PairTo.Value; sourceNavigationProperty.Multiplicity = targetInfo.Multiplicity; sourceNavigationProperty.PersistentTypeHasAssociations = typeAssociations; } if (targetNavigationProperty != null) { targetNavigationProperty.PersistentTypeOfNavigationProperty = targetEntity; targetNavigationProperty.Name = targetInfo.PairTo.Value; targetNavigationProperty.Multiplicity = sourceInfo.Multiplicity; targetNavigationProperty.PersistentTypeHasAssociations = typeAssociations; } typeAssociations.End1.PairTo.SetAsCustom(createPropertyEnd1 ? sourceNavigationProperty.Name : targetNavigationProperty.Name); typeAssociations.End2.PairTo.SetAsCustom(createPropertyEnd2 ? targetNavigationProperty.Name : sourceNavigationProperty.Name); return(typeAssociations); }
protected override void OnCopy(ModelElement sourceElement) { base.OnCopy(sourceElement); PersistentTypeHasAssociations sourceAssoc = (PersistentTypeHasAssociations)sourceElement; this.End1 = sourceAssoc.End1.Clone(); this.End1.AssignInternalsFrom(sourceAssoc.End1); this.End2 = sourceAssoc.End2.Clone(); this.End2.AssignInternalsFrom(sourceAssoc.End2); }
internal static string BuildAssociationName(PersistentType sourceEntity, PersistentType targetEntity) { string result = string.Format("{0}{1}", sourceEntity.Name, targetEntity.Name); bool nameUsed = true; var associationsLink = PersistentTypeHasAssociations.GetLinksToPersistentTypeAssociations(sourceEntity); while (nameUsed) { nameUsed = associationsLink.Any(item => Util.StringEqual(item.Name, result, true)); if (nameUsed) { result += "_1"; } } return(result); }
internal static ValidationResult ValidateAssociationName(PersistentTypeHasAssociations associations, string newName) { ValidationResult result = new ValidationResult(); var associationsLink = PersistentTypeHasAssociations.GetLinksToPersistentTypeAssociations(associations.SourcePersistentType); result.IsValid = associationsLink.Count(association => Util.StringEqual(association.Name, newName, true)) <= 1; if (!result.IsValid) { result.ErrorMessage = string.Format(ERROR_INVALID_NAME, associations.SourcePersistentType.Name, newName); result.ErrorCode = CODE_INVALID_NAME; result.ValidationElements = new ModelElement[] { associations }; } return(result); }
protected override void OnValueChanged(PersistentTypeHasAssociations element, string oldValue, string newValue) { if (!element.Store.InUndoRedoOrRollback && !element.IsValidationDisabled()) { // Hard validation of the new name. if (string.IsNullOrEmpty(newValue)) { throw new ArgumentException("The Name is required and cannot be an empty string.", newValue); } var validationResult = AssociationValidation.ValidateAssociationName(element, newValue); if (!validationResult.IsValid) { throw new ArgumentException(validationResult.ErrorMessage); } // Raise the NameChanged event for derived classes to act upon. //element.OnNameChanged(EventArgs.Empty); } // Always call the base class method. base.OnValueChanged(element, oldValue, newValue); }
private static void CustomReadPropertiesFromElements(SerializationContext serializationContext, PersistentTypeHasAssociations element, XmlReader reader) { Action useAssocAttrUpgradeFunc = () => { // this is here when converting from older versions than 1.0.5.0 to set 'UseAssociationAttribute' to true if (ModelUpgrader.Instance.DeserializingModelVersion < ModelUpgrader.Version_1_0_5_0) { ModelUpgrader.Instance.UpdateMakeChangesFlag(); } }; while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case "end1": if (reader.IsEmptyElement) { // No serialized value, must be default one. SerializationUtilities.Skip(reader); // Skip this tag. } else { OrmAssociationEnd end1 = new OrmAssociationEnd(element, "End1"); end1.DeserializeFromXml(reader, "end1"); element.End1 = end1; useAssocAttrUpgradeFunc(); SerializationUtilities.SkipToNextElement(reader); reader.SkipToNextElementFix(); } break; case "end2": if (reader.IsEmptyElement) { // No serialized value, must be default one. SerializationUtilities.Skip(reader); // Skip this tag. } else { OrmAssociationEnd end2 = new OrmAssociationEnd(element, "End2"); end2.DeserializeFromXml(reader, "end2"); element.End2 = end2; useAssocAttrUpgradeFunc(); SerializationUtilities.SkipToNextElement(reader); reader.SkipToNextElementFix(); } break; default: return; // Don't know this element. } } }
private static void CustomWritePropertiesAsElements(SerializationContext context, PersistentTypeHasAssociations element, XmlWriter writer) { // End1 if (!context.Result.Failed) { element.End1.SerializeToXml(writer, "end1"); } // End2 if (!context.Result.Failed) { element.End2.SerializeToXml(writer, "end2"); } }
/* * private ModelElement GetParentForScalarPropertyHasType(ScalarPropertyHasType childElement) * { * return childElement.ScalarProperty.PersistentType; * } */ #endregion Custom Source and Target for 'ScalarPropertyTypeOfConnector' #region Custom Source & Target for connector mapping 'AssociationConnector' private ModelElement GetParentForPersistentTypeHasAssociations(PersistentTypeHasAssociations childElement) { ModelElement element = childElement.SourcePersistentType; return(element); }
internal static ValidationResult ValidateAssociationName(PersistentTypeHasAssociations associations) { return(ValidateAssociationName(associations, associations.Name)); }