/// <summary> /// see whether the ReferentialConstraintIdentity in other contains a "covering" for /// this._referentialConstraintIdentity (for definition of "covering" see /// method ReferentialConstraintIdentity.IsCoveredBy(ReferentialConstraintIdentity)) /// </summary> internal bool IsCoveredBy(AssociationIdentityForReferentialConstraint other) { if (_referentialConstraintIdentity == null) { // if _referentialConstraintIdentity is null then anything covers it return true; } return _referentialConstraintIdentity.IsCoveredBy(other._referentialConstraintIdentity); }
/// <summary> /// see whether the ReferentialConstraintIdentity in other contains a "covering" for /// this._referentialConstraintIdentity (for definition of "covering" see /// method ReferentialConstraintIdentity.IsCoveredBy(ReferentialConstraintIdentity)) /// </summary> internal bool IsCoveredBy(AssociationIdentityForReferentialConstraint other) { if (_referentialConstraintIdentity == null) { // if _referentialConstraintIdentity is null then anything covers it return(true); } return(_referentialConstraintIdentity.IsCoveredBy(other._referentialConstraintIdentity)); }
internal static AssociationSummary ConstructAssociationSummary(EFArtifact artifact) { var ecm = artifact.MappingModel().FirstEntityContainerMapping; var summary = new AssociationSummary(); if (!EdmFeatureManager.GetForeignKeysInModelFeatureState(artifact.SchemaVersion).IsEnabled()) { if (ecm != null) { // Foreign keys in the model are not supported for this EDMX version. foreach (var asm in ecm.AssociationSetMappings()) { var cSideAssociation = asm.TypeName.Target; if (null != cSideAssociation) { var assocId = AssociationIdentityForAssociationSetMapping.CreateAssociationIdentity(asm); if (null != assocId) { summary.Add(cSideAssociation, assocId); } } } } } else { // Foreign keys in the model are supported for this EDMX version. foreach (var a in artifact.ConceptualModel().Associations()) { AssociationIdentity assocId = null; if (a.IsManyToMany == false && a.ReferentialConstraint != null) { assocId = AssociationIdentityForReferentialConstraint.CreateAssociationIdentity(a.ReferentialConstraint); } else { var asm = ModelHelper.FindAssociationSetMappingForConceptualAssociation(a); if (asm != null) { assocId = AssociationIdentityForAssociationSetMapping.CreateAssociationIdentity(asm); } } if (null != assocId) { summary.Add(a, assocId); } } } return(summary); }
/// <summary> /// returns true if the AssociationSetMapping is covered by the referential constraint. /// "covers" means that the /// 1. The columns mapped to the RC's principal keys match the columns mapped to the /// association's principal keys. /// 2. For each "pair" of properties that match between the RC & the ASM, the /// ASM's mapped column is contained in the dependent columns of the RC. /// </summary> private static bool IsCoveredBy(AssociationIdentityForReferentialConstraint assRC, AssociationIdentityForAssociationSetMapping asmid) { // get the principal end of the association var principalEnd = asmid.GetPrincipalEnd(); if (principalEnd == null) { return(false); } foreach (var p1 in principalEnd.GetPropertyMappingIdentities()) { // find the "equivalent" property mapping identity in the referential constraint // this is the property mapping identity whose Principal side columns match the // Principal side columns on this property of the association end. AssociationPropertyIdentity rcEquivalent = null; foreach (var p2 in assRC.ReferentialConstraintIdentity.PropertyIdentities) { if (AssociationPropertyIdentityComparer.Instance.Compare(p1, p2) == 0) { rcEquivalent = p2; break; } } // if we couldn't find an identity in the RC whose "Principal" columns matched those // in the principal association end, return false if (rcEquivalent == null) { return(false); } // // now check that for each database column in "Dependent" part of the association end, // (ie, each column mapped as part of the association set mapping) // it exists in the referential constraint's right columns (ie, the RC's dependent columns) // // Note that we don't do an equality check here, as the conceptual property in an RC // may be mapped to multiple tables, while the association set mapping will only ever be // mapped to one table. // foreach (var dc in p1.DependentColumns) { if (rcEquivalent.DependentColumns.Contains(dc) == false) { return(false); } } } return(true); }
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); }
/// <summary> /// returns true if the AssociationSetMapping is covered by the referential constraint. /// "covers" means that the /// 1. The columns mapped to the RC's principal keys match the columns mapped to the /// association's principal keys. /// 2. For each "pair" of properties that match between the RC & the ASM, the /// ASM's mapped column is contained in the dependent columns of the RC. /// </summary> private static bool IsCoveredBy(AssociationIdentityForReferentialConstraint assRC, AssociationIdentityForAssociationSetMapping asmid) { // get the principal end of the association var principalEnd = asmid.GetPrincipalEnd(); if (principalEnd == null) { return false; } foreach (var p1 in principalEnd.GetPropertyMappingIdentities()) { // find the "equivalent" property mapping identity in the referential constraint // this is the property mapping identity whose Principal side columns match the // Principal side columns on this property of the association end. AssociationPropertyIdentity rcEquivalent = null; foreach (var p2 in assRC.ReferentialConstraintIdentity.PropertyIdentities) { if (AssociationPropertyIdentityComparer.Instance.Compare(p1, p2) == 0) { rcEquivalent = p2; break; } } // if we couldn't find an identity in the RC whose "Principal" columns matched those // in the principal association end, return false if (rcEquivalent == null) { return false; } // // now check that for each database column in "Dependent" part of the association end, // (ie, each column mapped as part of the association set mapping) // it exists in the referential constraint's right columns (ie, the RC's dependent columns) // // Note that we don't do an equality check here, as the conceptual property in an RC // may be mapped to multiple tables, while the association set mapping will only ever be // mapped to one table. // foreach (var dc in p1.DependentColumns) { if (rcEquivalent.DependentColumns.Contains(dc) == false) { return false; } } } return true; }
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; }