private static TreeGridDesignerWatermarkInfo CreateWatermarkInfoPKToFKRC_WithASM(MappingDetailsWindowContainer windowContainer)
 {
     var errorMessage = String.Format(
         CultureInfo.CurrentCulture,
         Resources.MappingDetails_ReferentialConstraintOnAssociation_PKToFK_ASM,
         Resources.MappingDetails_ReferentialConstraintOnAssociation_PKToFK_ASM_Delete,
         Resources.MappingDetails_ReferentialConstraintOnAssociation_PKToFK_ASM_Display);
     var idx1 = errorMessage.IndexOf(
         Resources.MappingDetails_ReferentialConstraintOnAssociation_PKToFK_ASM_Delete, StringComparison.Ordinal);
     var idx2 = errorMessage.IndexOf(
         Resources.MappingDetails_ReferentialConstraintOnAssociation_PKToFK_ASM_Display, StringComparison.Ordinal);
     var watermarkInfo = new TreeGridDesignerWatermarkInfo(
         errorMessage,
         new TreeGridDesignerWatermarkInfo.LinkData(
             idx1,
             Resources.MappingDetails_ReferentialConstraintOnAssociation_PKToFK_ASM_Delete.Length,
             windowContainer.watermarkLabel_LinkClickedDeleteAssociation),
         new TreeGridDesignerWatermarkInfo.LinkData(
             idx2, Resources.MappingDetails_ReferentialConstraintOnAssociation_PKToFK_ASM_Display.Length,
             windowContainer.watermarkLabel_LinkClickedDisplayAssociation));
     return watermarkInfo;
 }
        internal static bool CanEditMappingsForAssociation(
            Association association, MappingDetailsWindowContainer windowContainer, ref TreeGridDesignerWatermarkInfo watermarkInfo,
            bool allowMappingEditWithFKs)
        {
            if (association == null)
            {
                throw new ArgumentNullException("association");
            }

            // make sure that we have an EntitySet (or can find one)
            if (association.AssociationSet == null)
            {
                var errorMessage = String.Format(
                    CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral,
                    Resources.MappingDetails_ErrMslCantFindAssociationSet);
                watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                return false;
            }

            var asms = association.AssociationSet.GetAntiDependenciesOfType<AssociationSetMapping>();

            var rc = association.ReferentialConstraint;
            if (rc != null)
            {
                // allowMappingEditWithFKs is an override flag that suppresses the following watermarks.
                if (allowMappingEditWithFKs == false)
                {
                    if (EdmFeatureManager.GetForeignKeysInModelFeatureState(association.Artifact.SchemaVersion)
                            .IsEnabled())
                    {
                        // set up watermarks association mapping window watermarks when FKs are supported
                        if (rc.IsPrimaryKeyToPrimaryKey())
                        {
                            if (asms.Count > 0)
                            {
                                watermarkInfo = CreateWatermarkInfoPKToPKRC_WithASM(windowContainer);
                            }
                            else
                            {
                                watermarkInfo = CreateWatermarkInfoPKToPKRC_NoASM(windowContainer);
                            }
                            return false;
                        }
                        else
                        {
                            if (asms.Count > 0)
                            {
                                watermarkInfo = CreateWatermarkInfoPKToFKRC_WithASM(windowContainer);
                            }
                            else
                            {
                                watermarkInfo = CreateWatermarkInfoPKToFKRC_NoASM();
                            }
                            return false;
                        }
                    }
                    else
                    {
                        // targeting netfx 3.5.  FKs are not supported
                        if (rc.IsPrimaryKeyToPrimaryKey() == false)
                        {
                            if (asms.Count > 0)
                            {
                                watermarkInfo = CreateWatermarkInfoPKToFKRC_WithASM(windowContainer);
                            }
                            else
                            {
                                watermarkInfo = CreateWatermarkInfoPKToFKRC_NoASM();
                            }
                            return false;
                        }
                    }
                }
            }

            // make sure that there is just one AssociationSetMapping for our set
            if (asms.Count > 1)
            {
                var errorMessage = String.Format(
                    CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral,
                    Resources.MappingDetails_ErrMslTooManyAssociationSetMappings);
                watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                return false;
            }
            else
            {
                foreach (var asm in asms)
                {
                    // if AssociationSetMapping contains QueryView
                    if (asm.HasQueryViewElement)
                    {
                        var errorMessage = String.Format(
                            CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral,
                            Resources.MappingDetails_ErrMslAssociationSetMappingHasQueryView);
                        watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                        return false;
                    }

                    // make sure that we fully resolve
                    var errorMsg = string.Empty;
                    if (EnsureResolvedStatus(asm, ref errorMsg) == false)
                    {
                        var errorMessage = String.Format(CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral, errorMsg);
                        watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                        return false;
                    }

                    // ensure that we don't have any C-side conditions
                    foreach (var cond in asm.Conditions())
                    {
                        if (cond.Name.RefName != null)
                        {
                            var errorMessage = String.Format(
                                CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral,
                                Resources.MappingDetails_ErrMslUnsupportedCondition);
                            watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                            return false;
                        }
                    }
                }
            }

            foreach (var associationEnd in association.AssociationEnds())
            {
                string duplicatePropertyName;
                var entityType = associationEnd.Type.Target;
                if (!CheckDuplicateEntityProperty(entityType, out duplicatePropertyName))
                {
                    var errorMessage = String.Format(
                        CultureInfo.CurrentCulture, Resources.MappingDetails_ErrDuplicatePropertyNameForAssociationEndEntity,
                        entityType.LocalName.Value, duplicatePropertyName);
                    errorMessage = String.Format(CultureInfo.CurrentCulture, Resources.MappingDetails_ErrMslGeneral, errorMessage);
                    watermarkInfo = new TreeGridDesignerWatermarkInfo(errorMessage);
                    return false;
                }
            }

            return true;
        }