// detects whether the S-side Property represents the dependent side of an Association (e.g. for Split Entity or TPT or C-side Conditions)
        private static bool IsDependentSidePropertyInAssociation(Property storageProperty)
        {
            if (storageProperty == null
                || storageProperty.EntityModel.IsCSDL)
            {
                Debug.Fail(
                    "should only receive a storage-side Property. Received property: "
                    + (storageProperty == null ? "NULL" : storageProperty.ToPrettyString()));
                return true; // returning true will mean this table's SGP settings will not be adjusted
            }

            foreach (var propRef in storageProperty.GetAntiDependenciesOfType<PropertyRef>())
            {
                var assoc = propRef.GetParentOfType(typeof(Association)) as Association;
                if (assoc == null)
                {
                    // no Association parent - so ignore this PropertyRef
                    continue;
                }

                foreach (var prop in assoc.DependentRoleProperties)
                {
                    if (storageProperty.Equals(prop))
                    {
                        // found storage property on the dependent side which is part of an association
                        return true;
                    }
                }
            }

            return false;
        }
        private static ICollection<Property> FindAllMappedSSidePropertiesForCSideProperty(Property cSideProp)
        {
            Debug.Assert(
                cSideProp.EntityModel.IsCSDL,
                "cSideProp with name " + cSideProp.NormalizedNameExternal + " is from SSDL, it must be from CSDL");

            ICollection<Property> sSideProps = new List<Property>();
            // return all the S-side Properties we find that map to
            // the cSideProp argument
            var scalarProps = cSideProp.GetAntiDependenciesOfType<ScalarProperty>();
            foreach (var scalarProp in scalarProps)
            {
                // if the scalarProp is not from a MappingFragment then ignore
                // (we want the column mapping, not e.g. an EndProperty mapping)
                if (!(scalarProp.Parent is MappingFragment))
                {
                    continue;
                }

                var sSideProp = scalarProp.ColumnName.Target;
                if (null != sSideProp)
                {
                    sSideProps.Add(sSideProp);
                }
            }

            return sSideProps;
        }
        // detects whether the S-side Property is within the table which provides storage for a C-side non-root EntityType (e.g. in a TPT hierarchy)
        private static bool IsStorageForNonRootEntityType(Property storageProperty)
        {
            if (storageProperty == null
                || storageProperty.EntityModel.IsCSDL)
            {
                Debug.Fail(
                    "should only receive a storage-side Property. Received property: "
                    + (storageProperty == null ? "NULL" : storageProperty.ToPrettyString()));
                return true; // returning true will mean this table's SGP settings will not be adjusted
            }

            foreach (var sp in storageProperty.GetAntiDependenciesOfType<ScalarProperty>())
            {
                var etm = sp.GetParentOfType(typeof(EntityTypeMapping)) as EntityTypeMapping;
                if (etm == null)
                {
                    // no EntityTypeMapping parent - so don't count this mapping
                    continue;
                }

                var etmKind = etm.Kind;
                if (EntityTypeMappingKind.Default != etmKind
                    && EntityTypeMappingKind.IsTypeOf != etmKind)
                {
                    // EntityTypeMapping is not for Default or IsTypeOf mapping - so don't count for finding the corresponding C-side EntityType
                    continue;
                }

                var cSideEntityType = etm.FirstBoundConceptualEntityType;
                if (cSideEntityType != null
                    && cSideEntityType.HasResolvableBaseType)
                {
                    var inheritanceStrategy = ModelHelper.DetermineCurrentInheritanceStrategy(cSideEntityType);
                    if (InheritanceMappingStrategy.TablePerType == inheritanceStrategy)
                    {
                        // C-side EntityType has TPT inheritance strategy and is not the base-most type in its inheritance hierarchy
                        return true;
                    }
                }
            }

            return false;
        }
        private static Property FindMappedCSidePropertyForSSideProperty(Property sSideProp)
        {
            Debug.Assert(
                !sSideProp.EntityModel.IsCSDL,
                "sSideProp with name " + sSideProp.NormalizedNameExternal + " is from CSDL, it must be from SSDL");

            // just return the first C-side Property we find that maps to
            // the sSideProp argument - just need type etc information from
            // it in order to clone a C-side Property in the existing artifact
            var scalarProps = sSideProp.GetAntiDependenciesOfType<ScalarProperty>();
            foreach (var scalarProp in scalarProps)
            {
                // if the scalarProp is not from a MappingFragment then ignore
                // (we want the column mapping, not e.g. an EndProperty mapping)
                if (!(scalarProp.Parent is MappingFragment))
                {
                    continue;
                }

                var cSideProp = scalarProp.Name.Target;
                if (null != cSideProp)
                {
                    return cSideProp;
                }
            }

            return null;
        }