Beispiel #1
0
        protected override void PostInvoke(CommandProcessorContext cpc)
        {
            // in the conceptual model, changing key states will impact MSL generated any
            // inferred ref constraints
            if (Property.EntityModel.IsCSDL)
            {
                EnforceEntitySetMappingRules.AddRule(cpc, Property.EntityType);
                InferReferentialConstraints.AddRule(cpc, Property.EntityType);

                // Add the integrity check to propagate the StoreGeneratedPattern value to the
                // S-side (may be altered by property being/not being a key) 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);
                    }
                }
            }

            base.PostInvoke(cpc);
        }
Beispiel #2
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            if (_entityProperty != null)
            {
                Debug.Assert(_entityProperty.EntityModel.IsCSDL, "_entityProperty should be from C-side model");
                ScalarProperty.Name.SetRefName(_entityProperty);
            }

            if (TableColumn != null)
            {
                Debug.Assert(TableColumn.EntityModel.IsCSDL != true, "_tableColumn should not be from C-side model");
                ScalarProperty.ColumnName.SetRefName(TableColumn);
            }

            XmlModelHelper.NormalizeAndResolve(ScalarProperty);

            // if we change a scalar in an association mapping, make sure that we still have good MSL
            if (ScalarProperty.EndProperty != null)
            {
                var asm = ScalarProperty.EndProperty.Parent as AssociationSetMapping;
                Debug.Assert(asm != null, "_sp.EndProperty parent is not an AssociationSetMapping");
                if (asm != null)
                {
                    EnforceAssociationSetMappingRules.AddRule(cpc, asm);

                    var assoc = asm.TypeName.Target;
                    Debug.Assert(assoc != null, "Could not resolve association reference");
                    if (assoc != null)
                    {
                        InferReferentialConstraints.AddRule(cpc, assoc);
                    }
                }
            }
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            var associationSetMapping = ModelHelper.FindAssociationSetMappingForConceptualAssociation(Association);

            if (associationSetMapping == null)
            {
                // This AssociationSetMapping does not exist, create it
                base.InvokeInternal(cpc);
                associationSetMapping = AssociationSetMapping;
                Debug.Assert(associationSetMapping != null, "Could not create AssociationSetMapping");
            }
            else
            {
                // The AssociationSetMapping already exists, update it
                associationSetMapping.Name.SetRefName(AssociationSet);
                associationSetMapping.TypeName.SetRefName(Association);
                associationSetMapping.StoreEntitySet.SetRefName(StorageEntitySet);

                XmlModelHelper.NormalizeAndResolve(associationSetMapping);

                Debug.Assert(associationSetMapping.Name.Target != null, "Could not resolve association set reference");
                Debug.Assert(associationSetMapping.TypeName.Target != null, "Could not resolve association type reference");
                Debug.Assert(associationSetMapping.StoreEntitySet.Target != null, "Could not resolve table reference");

                InferReferentialConstraints.AddRule(cpc, Association);
            }
        }
Beispiel #4
0
        protected override void PreInvoke(CommandProcessorContext cpc)
        {
            if (ScalarProperty.MappingFragment != null)
            {
                EnforceEntitySetMappingRules.AddRule(cpc, ScalarProperty);

                MFConceptualEntityTypeName = ScalarProperty.FirstBoundConceptualEntityType != null
                                                 ? ScalarProperty.FirstBoundConceptualEntityType.Name.Value
                                                 : null;
                MFConceptualPropertyName = ScalarProperty.Name.Target != null ? ScalarProperty.Name.Target.Name.Value : null;
                MFStorageEntitySetName   = ScalarProperty.BoundStorageEntityType != null
                                             ? ScalarProperty.BoundStorageEntityType.Name.Value
                                             : null;
                MFStorageColumnName             = ScalarProperty.ColumnName.Target != null ? ScalarProperty.ColumnName.Target.Name.Value : null;
                MFConceptualEntityTypeOwnerName = ScalarProperty.FirstBoundConceptualEntityType != null
                                                      ? ScalarProperty.FirstBoundConceptualEntityType.Name.Value
                                                      : null;
                MFComplexParentList =
                    ScalarProperty.GetParentComplexProperties(true)
                    .Where(cp => cp.Name.Target != null)
                    .Select(cp => cp.Name.Target.Name.Value);
            }
            else if (ScalarProperty.EndProperty != null)
            {
                var asm = ScalarProperty.EndProperty.Parent as AssociationSetMapping;
                Debug.Assert(asm != null, "this.ScalarProperty.EndProperty.Parent should be an AssociationSetMapping");
                if (asm != null)
                {
                    EnforceAssociationSetMappingRules.AddRule(cpc, asm);

                    var assoc = asm.TypeName.Target;
                    Debug.Assert(assoc != null, "the association set mapping does not have an Association");
                    if (assoc != null)
                    {
                        InferReferentialConstraints.AddRule(cpc, assoc);
                    }
                }
            }

            // Also add the integrity check to propagate the StoreGeneratedPattern value to the
            // S-side (may be altered by property mapping being deleted) 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 &&
                ScalarProperty.Name != null &&
                ScalarProperty.Name.Target != null)
            {
                var cProp = ScalarProperty.Name.Target as ConceptualProperty;
                Debug.Assert(
                    cProp != null, "ScalarProperty should have Name target with type " + typeof(ConceptualProperty).Name +
                    ", instead got type " + ScalarProperty.Name.Target.GetType().FullName);
                if (cProp != null)
                {
                    PropagateStoreGeneratedPatternToStorageModel.AddRule(cpc, cProp, true);
                }
            }

            base.PreInvoke(cpc);
        }
Beispiel #5
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // if we don't have an ECM yet, go create one
            if (EntityContainerMapping == null)
            {
                var createECM = new CreateEntityContainerMappingCommand(AssociationSet.Artifact);
                CommandProcessor.InvokeSingleCommand(cpc, createECM);
                EntityContainerMapping = createECM.EntityContainerMapping;
            }

            Debug.Assert(EntityContainerMapping != null, "EntityContainerMapping should not be null");
            if (EntityContainerMapping == null)
            {
                throw new CannotLocateParentItemException();
            }

            // create the ETM
            var asm = new AssociationSetMapping(EntityContainerMapping, null);

            asm.Name.SetRefName(AssociationSet);
            asm.TypeName.SetRefName(Association);
            asm.StoreEntitySet.SetRefName(StorageEntitySet);
            EntityContainerMapping.AddAssociationSetMapping(asm);

            XmlModelHelper.NormalizeAndResolve(asm);

            Debug.Assert(asm.Name.Target != null, "Could not resolve association set reference");
            Debug.Assert(asm.TypeName.Target != null, "Could not resolve association type reference");
            Debug.Assert(asm.StoreEntitySet.Target != null, "Could not resolve table reference");

            var assoc = asm.TypeName.Target;

            Debug.Assert(assoc != null, "Could not resolve association reference");
            if (assoc != null)
            {
                InferReferentialConstraints.AddRule(cpc, assoc);
            }

            _created = asm;
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            if (_endProperty == null)
            {
                var cmd = new CreateEndPropertyCommand(_associationSetMapping, _associationSetEnd);
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
                _endProperty = cmd.EndProperty;
            }

            Debug.Assert(_endProperty != null, "_endProperty should not be null");
            if (_endProperty == null)
            {
                throw new CannotLocateParentItemException();
            }

            var sp = new ScalarProperty(_endProperty, null);

            sp.Name.SetRefName(_entityProperty);
            sp.ColumnName.SetRefName(_tableColumn);
            _endProperty.AddScalarProperty(sp);

            XmlModelHelper.NormalizeAndResolve(sp);

            if (_enforceConstraints)
            {
                var asm = _endProperty.Parent as AssociationSetMapping;
                Debug.Assert(asm != null, "_endProperty parent is not an AssociationSetMapping");
                EnforceAssociationSetMappingRules.AddRule(cpc, asm);

                var assoc = asm.TypeName.Target;
                Debug.Assert(assoc != null, "_endProperty parent has a null Association");
                if (assoc != null)
                {
                    InferReferentialConstraints.AddRule(cpc, assoc);
                }
            }

            _created = sp;
        }
        protected override void PreInvoke(CommandProcessorContext cpc)
        {
            base.PreInvoke(cpc);

            OldRole         = End.Role.Value;
            OldMultiplicity = End.Multiplicity.Value;

            // Bug 599719: If this end's role equals the other end's role (within the association), we end up with the same normalized
            // names, and thus corrupt the symbol table. Attempts to rebind SingleItemBindings will corrupt the model. We have to
            // short-circuit the renaming here.
            var parentAssociation = End.Parent as Association;

            Debug.Assert(parentAssociation != null, "Where is the association for this association end?");
            if (parentAssociation != null)
            {
                var associationEnd = ModelHelper.FindAssociationEnd(parentAssociation, Role);
                if (associationEnd != null)
                {
                    var msg = String.Format(CultureInfo.CurrentCulture, Resources.Error_AssociationEndInAssocNotUnique, Role);
                    throw new CommandValidationFailedException(msg);
                }
            }

            if (string.IsNullOrEmpty(Multiplicity) == false &&
                !string.Equals(End.Multiplicity.Value, Multiplicity, StringComparison.OrdinalIgnoreCase))
            {
                End.Multiplicity.Value = Multiplicity;
                var association = End.Parent as Association;
                if (association != null &&
                    association.AssociationSet != null &&
                    association.AssociationSet.AssociationSetMapping != null)
                {
                    EnforceAssociationSetMappingRules.AddRule(cpc, association.AssociationSet.AssociationSetMapping);
                }
            }

            InferReferentialConstraints.AddRule(cpc, End.Parent as Association);
        }