protected override void PreParse() { Debug.Assert(State != EFElementState.Parsed, "this object should not already be in the parsed state"); ClearEFObjectCollection(_ends); ClearEFObject(_referentialConstraint); _referentialConstraint = null; base.PreParse(); }
internal static AssociationIdentity CreateAssociationIdentity(ReferentialConstraint rc) { if (rc == null) { Debug.Fail("You passed a null Referential Constraint to CreateAssociationIdentity!"); } else { var id = new AssociationIdentityForReferentialConstraint(rc); return id; } return null; }
protected override void OnChildDeleted(EFContainer efContainer) { var child = efContainer as AssociationEnd; if (child != null) { _ends.Remove(child); return; } if (efContainer == _referentialConstraint) { _referentialConstraint = null; return; } base.OnChildDeleted(efContainer); }
public ReferentialConstraintClipboardFormat(ReferentialConstraint referentialConstraint) : base(referentialConstraint) { _principalRole = referentialConstraint.Principal.Role.RefName; _principalProperties = new List <string>(referentialConstraint.Principal.PropertyRefs.Count); foreach (var propertyRef in referentialConstraint.Principal.PropertyRefs) { _principalProperties.Add(propertyRef.Name.RefName); if (_principalEntityName == null && propertyRef.Name.Target.EntityType != null) { _principalEntityName = propertyRef.Name.Target.EntityType.LocalName.Value; } } _dependentRole = referentialConstraint.Dependent.Role.RefName; _dependentProperties = new List <string>(referentialConstraint.Dependent.PropertyRefs.Count); foreach (var propertyRef in referentialConstraint.Dependent.PropertyRefs) { _dependentProperties.Add(propertyRef.Name.RefName); } }
public ReferentialConstraintClipboardFormat(ReferentialConstraint referentialConstraint) : base(referentialConstraint) { _principalRole = referentialConstraint.Principal.Role.RefName; _principalProperties = new List<string>(referentialConstraint.Principal.PropertyRefs.Count); foreach (var propertyRef in referentialConstraint.Principal.PropertyRefs) { _principalProperties.Add(propertyRef.Name.RefName); if (_principalEntityName == null && propertyRef.Name.Target.EntityType != null) { _principalEntityName = propertyRef.Name.Target.EntityType.LocalName.Value; } } _dependentRole = referentialConstraint.Dependent.Role.RefName; _dependentProperties = new List<string>(referentialConstraint.Dependent.PropertyRefs.Count); foreach (var propertyRef in referentialConstraint.Dependent.PropertyRefs) { _dependentProperties.Add(propertyRef.Name.RefName); } }
internal override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem) { if (elem.Name.LocalName == AssociationEnd.ElementName) { var assocEnd = new AssociationEnd(this, elem); _ends.Add(assocEnd); assocEnd.Parse(unprocessedElements); } else if (elem.Name.LocalName == ReferentialConstraint.ElementName) { if (_referentialConstraint != null) { var msg = String.Format( CultureInfo.CurrentCulture, Resources.TOO_MANY_REFERENTIAL_CONSTRAINTS_IN_ASSOCIATION, LocalName.Value); Artifact.AddParseErrorForObject(this, msg, ErrorCodes.TOO_MANY_REFERENTIAL_CONSTRAINTS_IN_ASSOCIATION); } else { _referentialConstraint = new ReferentialConstraint(this, elem); _referentialConstraint.Parse(unprocessedElements); } } else { return base.ParseSingleElement(unprocessedElements, elem); } return true; }
private AssociationIdentityForReferentialConstraint(ReferentialConstraint rc) { _referentialConstraintIdentity = ReferentialConstraintIdentity.CreateReferentialConstraintIdentity(rc); }
protected override void InvokeInternal(CommandProcessorContext cpc) { Debug.Assert( PrincipalEnd != null && DependentEnd != null, "InvokeInternal is called when PrincipalEnd or DependentEnd is null."); if (PrincipalEnd == null || DependentEnd == null) { throw new InvalidOperationException("InvokeInternal is called when PrincipalEnd or DependentEnd is null."); } var association = PrincipalEnd.Parent as Association; Debug.Assert( association != null && association == DependentEnd.Parent, "Association parent for both ends must agree and be not null"); var principalProps = PrincipalProperties.ToList(); var dependentProps = DependentProperties.ToList(); Debug.Assert(principalProps.Count == dependentProps.Count, "Number of principal and dependent properties must agree"); Debug.Assert(principalProps.Count > 0, "Number of properties must be positive"); var referentialConstraint = new ReferentialConstraint(association, null); association.ReferentialConstraint = referentialConstraint; XmlModelHelper.NormalizeAndResolve(referentialConstraint); var principalRole = new ReferentialConstraintRole(referentialConstraint, null); var dependentRole = new ReferentialConstraintRole(referentialConstraint, null); var service = cpc.EditingContext.GetEFArtifactService(); // we can't pass the type of referential constraint role ("Principal" or "Dependent") // in the constructor because XElement gets created in base constructor // before we have a chance to set any properties if (association.EntityModel.IsCSDL) { var csdlNamespaceName = SchemaManager.GetCSDLNamespaceName(service.Artifact.SchemaVersion); principalRole.XElement.Name = XName.Get(ReferentialConstraint.ElementNamePrincipal, csdlNamespaceName); dependentRole.XElement.Name = XName.Get(ReferentialConstraint.ElementNameDependent, csdlNamespaceName); } else { var ssdlNamespaceName = SchemaManager.GetSSDLNamespaceName(service.Artifact.SchemaVersion); principalRole.XElement.Name = XName.Get(ReferentialConstraint.ElementNamePrincipal, ssdlNamespaceName); dependentRole.XElement.Name = XName.Get(ReferentialConstraint.ElementNameDependent, ssdlNamespaceName); } principalRole.Role.SetRefName(PrincipalEnd); dependentRole.Role.SetRefName(DependentEnd); referentialConstraint.Principal = principalRole; referentialConstraint.Dependent = dependentRole; XmlModelHelper.NormalizeAndResolve(principalRole); XmlModelHelper.NormalizeAndResolve(dependentRole); for (var i = 0; i < principalProps.Count; i++) { principalRole.AddPropertyRef(principalProps[i]); dependentRole.AddPropertyRef(dependentProps[i]); } Debug.Assert( principalProps.Count == 0 || (principalRole.PropertyRefs.First().Name.Target != null && dependentRole.PropertyRefs.First().Name.Target != null), "Unresolved property references"); _createdRefConstraint = referentialConstraint; }
internal void SetCreatedReferentialConstraint(ReferentialConstraint refConstraint) { _createdRefConstraint = refConstraint; }
internal DeleteReferentialConstraintCommand(ReferentialConstraint referentialConstraint) : base(referentialConstraint) { }
/// <summary> /// Determines whether we should create an Association in the existing artifact given /// the ReferentialConstraint and AssociationEnd info from the temp artifact /// </summary> private static bool ShouldCreateAssociationGivenReferentialConstraint( ReferentialConstraint refConstraintInTempArtifact, AssociationEnd end1InTempArtifact, AssociationEnd end2InTempArtifact, ConceptualEntityType end1EntityTypeInExistingArtifact, ConceptualEntityType end2EntityTypeInExistingArtifact, out bool end1IsPrincipalEnd, out List<Property> principalPropertiesInExistingArtifact, out List<Property> dependentPropertiesInExistingArtifact, out List<string> unfoundPrincipalProperties, out List<string> unfoundDependentProperties) { end1IsPrincipalEnd = true; principalPropertiesInExistingArtifact = new List<Property>(); unfoundPrincipalProperties = new List<string>(); dependentPropertiesInExistingArtifact = new List<Property>(); unfoundDependentProperties = new List<string>(); ConceptualEntityType principalEndEntityType = null; ConceptualEntityType dependentEndEntityType = null; if (refConstraintInTempArtifact == null) { Debug.Fail("Should not have null ReferentialConstraint"); // no ReferentialConstraint in temp artifact to clone return false; } // determine which end is principal and which dependent if (refConstraintInTempArtifact.Principal.Role.Target == end1InTempArtifact) { Debug.Assert( refConstraintInTempArtifact.Dependent.Role.Target == end2InTempArtifact, "Unexpected end value for Dependent Role of ReferentialConstraint when Principal Role matches end1 from temp artifact"); end1IsPrincipalEnd = true; principalEndEntityType = end1EntityTypeInExistingArtifact; dependentEndEntityType = end2EntityTypeInExistingArtifact; } else if (refConstraintInTempArtifact.Principal.Role.Target == end2InTempArtifact) { Debug.Assert( refConstraintInTempArtifact.Dependent.Role.Target == end1InTempArtifact, "Unexpected end value for Dependent Role of ReferentialConstraint when Principal Role matches end2 from temp artifact"); end1IsPrincipalEnd = false; principalEndEntityType = end2EntityTypeInExistingArtifact; dependentEndEntityType = end1EntityTypeInExistingArtifact; } else { Debug.Fail("Couldn't identify principal & dependent end"); return false; } // find the principal properties in the existing doc to include in the referential constraint foreach (var tempProp in refConstraintInTempArtifact.Principal.Properties) { var prop = FindMatchingPropertyInExistingArtifactEntityType(tempProp, principalEndEntityType); if (prop != null) { principalPropertiesInExistingArtifact.Add(prop); } else { unfoundPrincipalProperties.Add(tempProp.LocalName.Value); } } // find the dependent properties in the existing doc to include in the referential constraint foreach (var tempProp in refConstraintInTempArtifact.Dependent.Properties) { var prop = FindMatchingPropertyInExistingArtifactEntityType(tempProp, dependentEndEntityType); if (prop != null) { dependentPropertiesInExistingArtifact.Add(prop); } else { unfoundDependentProperties.Add(tempProp.LocalName.Value); } } // return true if we found matching properties for all the properties in // both the principal and dependent ends, false otherwise if (unfoundDependentProperties.Count == 0 && unfoundPrincipalProperties.Count == 0) { return true; } else { return false; } }