コード例 #1
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // safety check, this should never be hit
            Debug.Assert(Property != null, "InvokeInternal is called when Property is null.");
            if (Property == null)
            {
                throw new InvalidOperationException("InvokeInternal is called when Property is null.");
            }

            var cmd = new UpdateDefaultableValueCommand <string>(Property.StoreGeneratedPattern, SgpValue);

            CommandProcessor.InvokeSingleCommand(cpc, cmd);

            // ensure view keys are propagated from C-side to S-side
            var cet = Property.EntityType as ConceptualEntityType;

            if (cet != null)
            {
                PropagateViewKeysToStorageModel.AddRule(cpc, cet);
            }

            // ensure StoreGeneratedPattern is propagated from C-side to S-side
            // unless we are part of an Update Model txn in which case there is no need
            // as the whole artifact has this integrity check applied by UpdateModelFromDatabaseCommand
            if (EfiTransactionOriginator.UpdateModelFromDatabaseId != cpc.OriginatorId)
            {
                var cProp = Property as ConceptualProperty;
                Debug.Assert(cProp != null, "expected Property of type ConceptualProperty, instead got type " + Property.GetType().FullName);
                if (cProp != null)
                {
                    PropagateStoreGeneratedPatternToStorageModel.AddRule(cpc, cProp, true);
                }
            }
        }
コード例 #2
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // safety check, this should never be hit
            Debug.Assert(Property != null, "InvokeInternal is called when property is null.");
            if (Property == null)
            {
                throw new InvalidOperationException("InvokeInternal is called when Property is null.");
            }

            if (Property.IsKeyProperty == IsKey)
            {
                // no change needed
                return;
            }

            if (IsKey)
            {
                if (Property.EntityType.Key == null)
                {
                    Property.EntityType.Key = new Key(Property.EntityType, null);
                }

                // make the key property non-nullable
                Property.Nullable.Value = BoolOrNone.FalseValue;
                Property.EntityType.Key.AddPropertyRef(Property);

                // normalize & resolve the key property
                XmlModelHelper.NormalizeAndResolve(Property.EntityType.Key);
            }
            else
            {
                var keyElement = Property.EntityType.Key;
                Debug.Assert(keyElement != null, "keyElement should not be null");

                if (keyElement != null)
                {
                    keyElement.RemovePropertyRef(Property);

                    if (!keyElement.Children.Any())
                    {
                        keyElement.Delete();
                    }
                    else
                    {
                        XmlModelHelper.NormalizeAndResolve(keyElement);
                    }
                }

                // if we are changing from key to non-key and this key is referenced by a principal end of
                // a ref constraint, then we want to delete that entry in the ref constraint
                if (IsKey == false && _deletePrincipalRCRefs)
                {
                    foreach (var pref in Property.GetAntiDependenciesOfType <PropertyRef>())
                    {
                        if (pref != null)
                        {
                            var role = pref.Parent as ReferentialConstraintRole;
                            if (role != null)
                            {
                                var rc = role.Parent as ReferentialConstraint;
                                if (rc != null &&
                                    rc.Principal == role)
                                {
                                    // property ref on a principal end, so delete it
                                    DeleteEFElementCommand.DeleteInTransaction(cpc, pref);
                                }
                            }
                        }
                    }
                }
            }

            var cet = Property.EntityType as ConceptualEntityType;

            if (cet != null)
            {
                PropagateViewKeysToStorageModel.AddRule(cpc, cet);
            }
        }
コード例 #3
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            Debug.Assert(
                ModeValue == Mode.EntityType || ModeValue == Mode.MappingFragment || ModeValue == Mode.ComplexProperty,
                "Unknown mode set in CreateFragmentScalarPropertyCommand");

            if (ModeValue == Mode.EntityType)
            {
                // safety check, this should never be hit
                if (ConceptualEntityType == null ||
                    Property == null ||
                    TableColumn == null)
                {
                    throw new ArgumentNullException();
                }

                _sp = CreateScalarPropertyUsingEntity(
                    cpc,
                    ConceptualEntityType, Property, TableColumn);
            }
            else if (ModeValue == Mode.ComplexProperty)
            {
                // safety check, this should never be hit
                if (ComplexProperty == null ||
                    Property == null ||
                    TableColumn == null)
                {
                    throw new ArgumentNullException();
                }

                _sp = CreateScalarPropertyUsingComplexProperty(ComplexProperty, Property, TableColumn);
            }
            else
            {
                // safety check, this should never be hit
                if (_mappingFragment == null ||
                    Property == null ||
                    TableColumn == null)
                {
                    throw new ArgumentNullException();
                }

                _sp = CreateScalarPropertyUsingFragment(_mappingFragment, Property, TableColumn);
            }

            if (_sp.MappingFragment != null &&
                _sp.MappingFragment.EntityTypeMapping != null &&
                _sp.MappingFragment.EntityTypeMapping.FirstBoundConceptualEntityType != null)
            {
                PropagateViewKeysToStorageModel.AddRule(cpc, _sp.MappingFragment.EntityTypeMapping.FirstBoundConceptualEntityType);

                // Also add the integrity check to propagate the StoreGeneratedPattern value to the
                // S-side (may be altered by property being/not being mapped) unless we are part
                // of an Update Model txn in which case there is no need as the whole artifact has
                // this integrity check applied by UpdateModelFromDatabaseCommand
                if (EfiTransactionOriginator.UpdateModelFromDatabaseId != cpc.OriginatorId &&
                    _sp.Name != null &&
                    _sp.Name.Target != null)
                {
                    var cProp = _sp.Name.Target as ConceptualProperty;
                    Debug.Assert(
                        cProp != null,
                        " ScalarProperty should have Name target with type ConceptualProperty, instead got type "
                        + _sp.Name.Target.GetType().FullName);
                    if (cProp != null)
                    {
                        PropagateStoreGeneratedPatternToStorageModel.AddRule(cpc, cProp, true);
                    }
                }
            }
        }