Exemple #1
0
        private static Condition CreateConditionUsingEntity(
            CommandProcessorContext cpc, EntityType conceptualEntityType, Property tableColumn, bool?isNull, string conditionValue)
        {
            // first see if we have a Default ETM
            var mappingFragment = ModelHelper.FindMappingFragment(
                cpc, conceptualEntityType, tableColumn.EntityType, EntityTypeMappingKind.Default, false);

            if (mappingFragment == null)
            {
                // if we don't have a default, then find or create an IsTypeOf ETM to put this in
                mappingFragment = ModelHelper.FindMappingFragment(
                    cpc, conceptualEntityType, tableColumn.EntityType, EntityTypeMappingKind.IsTypeOf, true);
            }
            Debug.Assert(mappingFragment != null, "Failed to create the MappingFragment to house this Condition");
            if (mappingFragment == null)
            {
                throw new ParentItemCreationFailureException();
            }

            // create the condition
            var cond = CreateConditionUsingFragment(mappingFragment, tableColumn, isNull, conditionValue);

            // see if any conditions need to move now
            EnforceEntitySetMappingRules.AddRule(cpc, cond);

            return(cond);
        }
Exemple #2
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);
        }
 protected override void PreInvoke(CommandProcessorContext cpc)
 {
     // save off the deleted entity type name
     SaveDeletedInformation();
     EnforceEntitySetMappingRules.AddRule(cpc, EntityTypeMapping.EntitySetMapping);
     base.PreInvoke(cpc);
 }
        private static ScalarProperty CreateScalarPropertyUsingEntity(
            CommandProcessorContext cpc, EntityType conceptualEntityType, Property entityProperty, Property tableColumn)
        {
            // the S-Side entity
            var storageEntityType = tableColumn.Parent as EntityType;

            Debug.Assert(storageEntityType != null, "tableColumn.Parent should be an EntityType");

            // get the fragment to use
            var mappingFragment = ModelHelper.FindMappingFragment(cpc, conceptualEntityType, tableColumn.EntityType, true);

            Debug.Assert(mappingFragment != null, "Failed to create the MappingFragment to house this ScalarProperty");
            if (mappingFragment == null)
            {
                throw new ParentItemCreationFailureException();
            }

            // now go do the real work
            var sp = CreateScalarPropertyUsingFragment(mappingFragment, entityProperty, tableColumn);

            // enforce our mapping rules
            EnforceEntitySetMappingRules.AddRule(cpc, sp);

            return(sp);
        }
Exemple #5
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);
        }
Exemple #6
0
 protected override void PostInvoke(CommandProcessorContext cpc)
 {
     // changing abstractness will impact the MSL generated
     if (EntityType != null)
     {
         EnforceEntitySetMappingRules.AddRule(cpc, EntityType.EntitySet);
     }
 }
        protected override void PreInvoke(CommandProcessorContext cpc)
        {
            Debug.Assert(_derivedType.BaseType.Target != null, "The derivedType passed does not derive from any type");
            SaveDeletedInformation();

            base.PreInvoke(cpc);

            // register to enforce MSL rules on the existing entity set, which won't include the derived type any more
            // after this command completes
            EnforceEntitySetMappingRules.AddRule(cpc, _derivedType.EntitySet);
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // don't do anything if we are trying to set the same thing
            if (string.Compare(Condition.ColumnName.RefName, NewStorageProperty.LocalName.Value, StringComparison.CurrentCulture) != 0)
            {
                Condition.ColumnName.SetRefName(NewStorageProperty);
                XmlModelHelper.NormalizeAndResolve(Condition);

                EnforceEntitySetMappingRules.AddRule(cpc, Condition);
            }
        }
        protected override void PreInvoke(CommandProcessorContext cpc)
        {
            if (MappingFragment.EntityTypeMapping != null &&
                MappingFragment.EntityTypeMapping.EntitySetMapping != null)
            {
                ConceptualEntityTypeName = MappingFragment.EntityTypeMapping.FirstBoundConceptualEntityType != null
                                               ? MappingFragment.EntityTypeMapping.FirstBoundConceptualEntityType.Name.Value
                                               : null;
                StorageEntitySetName = MappingFragment.StoreEntitySet.Target != null
                                           ? MappingFragment.StoreEntitySet.Target.Name.Value
                                           : null;

                EnforceEntitySetMappingRules.AddRule(cpc, MappingFragment.EntityTypeMapping.EntitySetMapping);
            }

            base.PreInvoke(cpc);
        }
        protected override void PostInvoke(CommandProcessorContext cpc)
        {
            // now that we have a new entity set, make sure that it and any derived types use correct MSL
            EnforceEntitySetMappingRules.AddRule(cpc, _derivedType.EntitySet);

            // see if this type is used by association ends; since we deleted the inheritance, this entity got
            // a new EntitySet so we need to change any EntitySet references for corresponding AssociationSetEnds to the new one
            Association association = null;

            foreach (var end in _derivedType.GetAntiDependenciesOfType <AssociationEnd>())
            {
                foreach (var setEnd in end.GetAntiDependenciesOfType <AssociationSetEnd>())
                {
                    setEnd.EntitySet.SetRefName(_derivedType.EntitySet);
                    XmlModelHelper.NormalizeAndResolve(setEnd);
                }

                association = end.Parent as Association;
            }

            // try to recreate the AssociationSetMapping if one exists
            if (association != null &&
                association.AssociationSet != null &&
                association.AssociationSet.AssociationSetMapping != null &&
                association.AssociationSet.AssociationSetMapping.XObject != null)
            {
                // store off the entity set for later
                var storeEntitySet = association.AssociationSet.AssociationSetMapping.StoreEntitySet.Target;

                // delete it
                DeleteEFElementCommand.DeleteInTransaction(cpc, association.AssociationSet.AssociationSetMapping);

                // create a new one (if we can)
                if (storeEntitySet != null &&
                    storeEntitySet.EntityType.Target != null)
                {
                    var set = storeEntitySet.EntityType.Target as StorageEntityType;
                    Debug.Assert(storeEntitySet.EntityType.Target == null || set != null, "EntityType is not StorageEntityType");

                    CreateAssociationSetMappingCommand.CreateAssociationSetMappingAndIntellimatch(cpc, association, set);
                }
            }

            base.PostInvoke(cpc);
        }
Exemple #11
0
        /// <summary>
        ///     We override this method because we need to do some extra things before
        ///     the normal PreInvoke gets called and our antiDeps are removed
        /// </summary>
        /// <param name="cpc"></param>
        protected override void PreInvoke(CommandProcessorContext cpc)
        {
            // save off the deleted entity type name
            SaveDeletedInformation();

            // enforce our mapping rules for C-side entities
            if (EntityType.EntityModel.IsCSDL)
            {
                EnforceEntitySetMappingRules.AddRule(cpc, EntityType);
                // remove base type for all derived EntityTypes
                var cet = EntityType as ConceptualEntityType;
                Debug.Assert(cet != null, "EntityType is not a ConceptualEntityType");

                foreach (var derivedType in cet.ResolvableDirectDerivedTypes)
                {
                    var cmd = new DeleteInheritanceCommand(derivedType);
                    CommandProcessor.InvokeSingleCommand(cpc, cmd);
                }
            }
            base.PreInvoke(cpc);
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // see if we have the ETM we need, if not create it
            if (_entityTypeMapping == null)
            {
                _entityTypeMapping = ModelHelper.FindEntityTypeMapping(cpc, ConceptualEntityType, _entityTypeMappingKind, true);
            }

            // make sure it was created
            Debug.Assert(_entityTypeMapping != null, "We should have created an EntityTypeMapping if needed, it is still null.");
            if (_entityTypeMapping == null)
            {
                throw new CannotLocateParentItemException();
            }

            _createdMappingFragment = new MappingFragment(_entityTypeMapping, null);
            _createdMappingFragment.StoreEntitySet.SetRefName(StorageEntitySet);
            _entityTypeMapping.AddMappingFragment(_createdMappingFragment);

            XmlModelHelper.NormalizeAndResolve(_createdMappingFragment);

            EnforceEntitySetMappingRules.AddRule(cpc, _entityTypeMapping.EntitySetMapping);
        }
        protected override void PreInvoke(CommandProcessorContext cpc)
        {
            var fragment = Condition.MappingFragment;

            if (fragment != null)
            {
                EnforceEntitySetMappingRules.AddRule(cpc, Condition);
            }

            // Save off the conceptual and storage entity names
            var conceptualEntityType = Condition.FirstBoundConceptualEntityType;
            var storageEntityType    = Condition.BoundStorageEntityType;

            if (conceptualEntityType != null &&
                storageEntityType != null &&
                Condition.ColumnName.Target != null)
            {
                OriginalConceptualEntityName = conceptualEntityType.Name.Value;
                OriginalStorageEntityName    = storageEntityType.Name.Value;
                OriginalStoragePropertyName  = Condition.ColumnName.Target.Name.Value;
            }
            base.PreInvoke(cpc);
        }
        protected override void PreInvoke(CommandProcessorContext cpc)
        {
            base.PreInvoke(cpc);

            // you cannot use this command with a type that already has a base class; throwing here
            // because its not a good idea to throw an exception in a c'tor
            if (EntityToBeDerived == null ||
                EntityToBeDerived.BaseType.Target != null)
            {
                throw new InvalidOperationException();
            }

            EnforceEntitySetMappingRules.AddRule(cpc, BaseType.EntitySet);

            // see if this type is used by association ends; since we are creating an inheritance
            // we need to change any AssociationSetEnd references from the current EntitySet to the
            // new baseType's EntitySet (the derived type's EntitySet will be deleted)
            var associationsToUpdate = new HashSet <Association>();

            if (EntityToBeDerived.EntitySet != null)
            {
                var associationSetEndsToUpdate = EntityToBeDerived.EntitySet.GetAntiDependenciesOfType <AssociationSetEnd>();
                foreach (var setEnd in associationSetEndsToUpdate)
                {
                    setEnd.EntitySet.SetRefName(BaseType.EntitySet);
                    XmlModelHelper.NormalizeAndResolve(setEnd);

                    var aSet = setEnd.Parent as AssociationSet;
                    if (aSet != null)
                    {
                        if (aSet.Association.Target != null)
                        {
                            associationsToUpdate.Add(aSet.Association.Target);
                        }
                    }
                }
            }

            foreach (var association in associationsToUpdate)
            {
                // try to recreate the AssociationSetMapping if one exists
                if (association != null &&
                    association.AssociationSet != null &&
                    association.AssociationSet.AssociationSetMapping != null &&
                    association.AssociationSet.AssociationSetMapping.XObject != null)
                {
                    // store off the entity set for later
                    var storeEntitySet = association.AssociationSet.AssociationSetMapping.StoreEntitySet.Target;

                    // delete it
                    DeleteEFElementCommand.DeleteInTransaction(cpc, association.AssociationSet.AssociationSetMapping);

                    // create a new one (if we can)
                    if (storeEntitySet != null &&
                        storeEntitySet.EntityType.Target != null)
                    {
                        var set = storeEntitySet.EntityType.Target as StorageEntityType;
                        Debug.Assert(set != null, "EntityType is not StorageEntityType");
                        CreateAssociationSetMappingCommand.CreateAssociationSetMappingAndIntellimatch(cpc, association, set);
                    }
                }
            }
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            var service  = cpc.EditingContext.GetEFArtifactService();
            var artifact = service.Artifact;

            Debug.Assert(artifact != null, "Null Artifact");
            if (null == artifact)
            {
                return;
            }

            // construct a mapping of the existing model's C-side objects
            // and their S-side identities before anything is updated
            var existingModel = new ExistingModelSummary(artifact);

            // replace the old SSDL with the new and fixup any references
            // in the MSL that broke because of the replacement of the SSDL
            // (i.e. the S-side Alias and S-side EntityContainer name)
            var replaceSsdlCommand = new ReplaceSsdlCommand(_newArtifactFromDB.StorageModel());

            CommandProcessor.InvokeSingleCommand(cpc, replaceSsdlCommand);

            // remove any mappings with references which no longer work
            // with the new SSDL
            var deleteUnboundMappingsCommand = new DeleteUnboundMappingsCommand();

            CommandProcessor.InvokeSingleCommand(cpc, deleteUnboundMappingsCommand);

            // remove any mappings which should no longer be mapped with the new SSDL
            // but actually are because a new S-side object with identical name
            // but different identity has been added
            var deleteChangedIdentityMappingsCommand = new DeleteChangedIdentityMappingsCommand(existingModel);

            CommandProcessor.InvokeSingleCommand(cpc, deleteChangedIdentityMappingsCommand);

            // from the temp model for the updated database determine which
            // C-side objects need to be added/updated and then update the
            // C- and M- side models appropriately
            var modelFromUpdatedDatabase = new UpdatedModelSummary(_newArtifactFromDB);
            var updateCsdlAndMslCommand  =
                new UpdateConceptualAndMappingModelsCommand(existingModel, modelFromUpdatedDatabase);

            CommandProcessor.InvokeSingleCommand(cpc, updateCsdlAndMslCommand);

            // fix up Function Import parameters and add integrity checks
            if (artifact.MappingModel() != null &&
                artifact.MappingModel().FirstEntityContainerMapping != null)
            {
                // Function Import parameters are now out-of-date compared to the updated Function ones.
                // We need to update them as otherwise there is no way to do so using Escher.
                foreach (var fim in artifact.MappingModel().FirstEntityContainerMapping.FunctionImportMappings())
                {
                    if (null != fim.FunctionImportName &&
                        null != fim.FunctionImportName.Target &&
                        null != fim.FunctionName &&
                        null != fim.FunctionName.Target)
                    {
                        CreateFunctionImportCommand.UpdateFunctionImportParameters(
                            cpc, fim.FunctionImportName.Target, fim.FunctionName.Target);
                    }
                }

                // Add integrity checks to enforce mapping rules
                foreach (var esm in artifact.MappingModel().FirstEntityContainerMapping.EntitySetMappings())
                {
                    EnforceEntitySetMappingRules.AddRule(cpc, esm);
                }

                // add the integrity check to propagate all appropriate StoreGeneratedPattern values to the S-side
                // Note: should not propagate "None"/defaulted values to prevent those C-side values overwriting
                // correctly updated S-side StoreGeneratedPattern values which were just received from the runtime
                PropagateStoreGeneratedPatternToStorageModel.AddRule(cpc, artifact, false);

                // Add integrity check to enforce synchronizing C-side Property facets to S-side values
                var shouldSynchronizePropertyFacets = ModelHelper.GetDesignerPropertyValueFromArtifactAsBool(
                    OptionsDesignerInfo.ElementName,
                    OptionsDesignerInfo.AttributeSynchronizePropertyFacets, OptionsDesignerInfo.SynchronizePropertyFacetsDefault(artifact),
                    artifact);
                if (shouldSynchronizePropertyFacets)
                {
                    PropagateStoragePropertyFacetsToConceptualModel.AddRule(cpc, artifact);
                }
            }
        }