protected override void PreParse() { Debug.Assert(State != EFElementState.Parsed, "this object should not already be in the parsed state"); ClearEFObject(_principal); _principal = null; ClearEFObject(_dependent); _dependent = null; base.PreParse(); }
protected override void OnChildDeleted(EFContainer efContainer) { if (efContainer == _principal) { _principal = null; return; } if (efContainer == _dependent) { _dependent = null; return; } base.OnChildDeleted(efContainer); }
internal override bool ParseSingleElement(ICollection <XName> unprocessedElements, XElement elem) { if (elem.Name.LocalName == ElementNamePrincipal) { _principal = new ReferentialConstraintRole(this, elem); _principal.Parse(unprocessedElements); } else if (elem.Name.LocalName == ElementNameDependent) { _dependent = new ReferentialConstraintRole(this, elem); _dependent.Parse(unprocessedElements); } else { return(base.ParseSingleElement(unprocessedElements, elem)); } return(true); }
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 override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem) { if (elem.Name.LocalName == ElementNamePrincipal) { _principal = new ReferentialConstraintRole(this, elem); _principal.Parse(unprocessedElements); } else if (elem.Name.LocalName == ElementNameDependent) { _dependent = new ReferentialConstraintRole(this, elem); _dependent.Parse(unprocessedElements); } else { return base.ParseSingleElement(unprocessedElements, elem); } return true; }
private static bool HasIdenticalKeyToEntityType(ReferentialConstraintRole refConstraintRole) { if (null == refConstraintRole || null == refConstraintRole.Role || null == refConstraintRole.Role.Target || null == refConstraintRole.Role.Target.Type || null == refConstraintRole.Role.Target.Type.Target) { // no resolved EntityType - cannot match keys return false; } // find list of properties representing PK of EntityType var et = refConstraintRole.Role.Target.Type.Target; var cet = et as ConceptualEntityType; Debug.Assert( cet != null, "expected EntityType of type ConceptualEntityType, instead type is " + (et == null ? "null" : et.GetType().FullName)); var etKeyProps = new HashSet<Property>(); foreach (var p in cet.ResolvableTopMostBaseType.ResolvableKeys) { etKeyProps.Add(p); } // find list of properties referenced in the ReferentialConstraintRole var refConstraintProps = new HashSet<Property>(); foreach (var propRef in refConstraintRole.PropertyRefs) { if (null != propRef.Name.Target) { refConstraintProps.Add(propRef.Name.Target); } } // if the counts of properties in refConstraintProps and etKeyProps // are not the same then the keys cannot be identical if (etKeyProps.Count != refConstraintProps.Count) { return false; } // remove all the refConstraintProps properties from etKeyProps, // if any are left then the key has not been covered etKeyProps.ExceptWith(refConstraintProps); return (etKeyProps.Count == 0); }