internal PropagateStoreGeneratedPatternToStorageModel(
     CommandProcessorContext cpc, StorageProperty storageProperty, bool propagateNoneSGP)
 {
     _cpc = cpc;
     _storageProperty = storageProperty;
     _propagateNoneSGP = propagateNoneSGP;
 }
Esempio n. 2
0
        internal override bool ParseSingleElement(ICollection <XName> unprocessedElements, XElement elem)
        {
            if (elem.Name.LocalName == Property.ElementName)
            {
                Property prop = null;

                prop = new StorageProperty(this, elem);

                prop.Parse(unprocessedElements);
                AddProperty(prop);
            }
            else
            {
                return(base.ParseSingleElement(unprocessedElements, elem));
            }
            return(true);
        }
        internal override bool ParseSingleElement(ICollection<XName> unprocessedElements, XElement elem)
        {
            if (elem.Name.LocalName == Property.ElementName)
            {
                Property prop = null;

                prop = new StorageProperty(this, elem);

                prop.Parse(unprocessedElements);
                AddProperty(prop);
            }
            else
            {
                return base.ParseSingleElement(unprocessedElements, elem);
            }
            return true;
        }
        private void PropagateConceptualSGPToStorageProperty(StorageProperty sProp)
        {
            if (null == sProp)
            {
                Debug.Fail("null StorageProperty");
                return;
            }

            if (sProp.IsDisposed)
            {
                // this StorageProperty was deleted after this integrity check was created but
                // before it was invoked - not an error - just ignore this property
                return;
            }

            if (sProp.IsKeyProperty)
            {
                if (IsStorageForNonRootEntityType(sProp))
                {
                    // this StorageProperty is for a key column on a table which acts as storage for a non-root EntityType
                    // (e.g. in a TPT hierarchy). So do not set SGP - it should be set only on the root column.
                    return;
                }

                if (IsDependentSidePropertyInAssociation(sProp))
                {
                    // this StorageProperty is used in the dependent side of an Association.
                    // So do not set SGP - it should be set only on the principal side.
                    return;
                }
            }

            // loop over ConceptualProperties mapped to this StorageProperty
            foreach (var sp in sProp.GetAntiDependenciesOfType<ScalarProperty>())
            {
                // only use ScalarProperty elements inside an EntitySetMapping or EntityTypeMapping
                // (MappingFragment is only used by those types of mappings)
                if (null != sp.GetParentOfType(typeof(MappingFragment)))
                {
                    // only propagate values from non-key C-side properties
                    var cProp = sp.Name.Target as ConceptualProperty;
                    if (cProp != null)
                    {
                        var cSideSGPValue = cProp.StoreGeneratedPattern.Value;
                        if (_propagateNoneSGP
                            || false == ModelConstants.StoreGeneratedPattern_None.Equals(cSideSGPValue, StringComparison.Ordinal))
                        {
                            // have found a C-side property whose SGP value should be propagated
                            if (false == cSideSGPValue.Equals(sProp.StoreGeneratedPattern.Value, StringComparison.Ordinal))
                            {
                                var cmd = new UpdateDefaultableValueCommand<string>(sProp.StoreGeneratedPattern, cSideSGPValue);
                                CommandProcessor.InvokeSingleCommand(_cpc, cmd);
                            }

                            return;
                        }

                        // Otherwise have found a C-side SGP but it has value "None" and have been told not to propagate "None" values
                        // (will apply to where SGP is absent too since "None" is the default value).
                        // So loop round looking for the next C-side SGP to see if it applies.
                    }
                }
            }
        }
 private static Property CreateStorageProperty(StorageEntityType parentEntity, string name, string type)
 {
     var property = new StorageProperty(parentEntity, null);
     property.LocalName.Value = name;
     property.Type.Value = type;
     return property;
 }