internal override void DeleteModelItem(CommandProcessorContext cpc)
        {
            Debug.Assert(ModelItem != null, "We are trying to delete a null ModelItem");

            if (IsModelItemDeleted() == false)
            {
                // first cache the property
                _property = ScalarProperty.Name.Target;

                // create a context if we weren't passed one
                if (cpc == null)
                {
                    cpc = new CommandProcessorContext(
                        Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_ChangeScalarProperty);
                }

                // use the item's delete command
                var deleteCommand = ScalarProperty.GetDeleteCommand();
                deleteCommand.PostInvokeEvent += (o, eventsArgs) => { ModelItem = null; };

                DeleteEFElementCommand.DeleteInTransaction(cpc, deleteCommand);
            }

            // if IsModelItemDeleted == true, just make sure that it is null anyways
            ModelItem = null;
        }
Esempio n. 2
0
        // <summary>
        //     NOTE: We don't call this.Parent.RemoveChild(this) because this is always called from the MappingEFElement.Delete() method
        //     which will remove this item from the parent.
        // </summary>
        internal override void DeleteModelItem(CommandProcessorContext cpc)
        {
            Debug.Assert(ModelItem != null, "We are trying to delete a null ModelItem");
            if (IsModelItemDeleted() == false)
            {
                // create a context if we weren't passed one
                if (cpc == null)
                {
                    cpc = new CommandProcessorContext(
                        Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_DeleteMappingFragment);
                }

                var fragment = ModelHelper.FindMappingFragment(
                    cpc, MappingConceptualEntityType.ConceptualEntityType, StorageEntityType, false);
                Debug.Assert(fragment != null, "could not find MappingFragment for StorageEntityType " + StorageEntityType.ToPrettyString());
                if (fragment != null)
                {
                    // use the item's delete command
                    var deleteCommand = fragment.GetDeleteCommand();
                    deleteCommand.PostInvokeEvent += (o, eventsArgs) =>
                    {
                        ModelItem = null;
                        ColumnMappings.ModelItem = null;
                    };

                    DeleteEFElementCommand.DeleteInTransaction(cpc, deleteCommand);
                }
            }

            // if IsModelItemDeleted == true, just make sure that it is null anyways
            ModelItem = null;
            ColumnMappings.ModelItem = null;
        }
Esempio n. 3
0
        /// <summary>
        ///     The mapping view model contains a MappingEndScalarProperty for every key in each end.  The user can clear out the
        ///     underlying scalar property, but that doesn’t remove or add the MappingEndScalarProperty.  We need the placeholder
        ///     in the view model to show the nodes in the Trid even if there isn’t a mapping.  Thus, we don't need to call
        ///     this.Parent.RemoveChild(this) as we want to leave the placeholder.
        /// </summary>
        internal override void DeleteModelItem(CommandProcessorContext cpc)
        {
            Debug.Assert(ModelItem != null, "We are trying to delete a null ModelItem");
            if (IsModelItemDeleted() == false)
            {
                // since we are deleting the SP, we need to go back to our "base-less" mode
                // where the property info is returned as instance strings - cache off the data
                var property     = Property;
                var propertyType = PropertyType;

                // create a context if we weren't passed one
                if (cpc == null)
                {
                    cpc = new CommandProcessorContext(
                        Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_DeleteScalarProperty);
                }

                // use the item's delete command
                var deleteCommand = ScalarProperty.GetDeleteCommand();
                deleteCommand.PostInvokeEvent += (o, eventsArgs) => { ModelItem = null; };

                DeleteEFElementCommand.DeleteInTransaction(cpc, deleteCommand);

                // restore the data so the display is correct
                Property     = property;
                PropertyType = propertyType;
            }

            // if IsModelItemDeleted == true, just make sure that it is null anyways
            ModelItem = null;
        }
Esempio n. 4
0
        // <summary>
        //     The parent item for the function mapping view model always has 3 children; insert, update and delete.  If there isn’t
        //     a function mapped for any of these, then there is still a view model item since we want to display the ‘creator node’ text.
        //     Thus, we don't call this.Parent.RemoveChild(this).
        // </summary>
        internal override void DeleteModelItem(CommandProcessorContext cpc)
        {
            Debug.Assert(ModelItem != null, "We are trying to delete a null ModelItem");
            if (IsModelItemDeleted() == false)
            {
                // create a context if we weren't passed one
                if (cpc == null)
                {
                    cpc = new CommandProcessorContext(
                        Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_DeleteFunctionMapping);
                }

                // use the item's delete command
                var deleteCommand = ModificationFunction.GetDeleteCommand(MappingFunctionEntityType.EntityType, Function, _functionType);
                deleteCommand.PostInvokeEvent += (o, eventsArgs) =>
                {
                    ModelItem = null;
                    ClearChildren();
                };

                DeleteEFElementCommand.DeleteInTransaction(cpc, deleteCommand);
            }

            // if IsModelItemDeleted == true, just make sure that it is null anyways
            ModelItem = null;
        }
Esempio n. 5
0
        internal override void Invoke(CommandProcessorContext cpc)
        {
            var viewModel = _property.GetRootViewModel();

            Debug.Assert(viewModel != null, "Unable to find root view model from navigation property:" + _property.Name);
            if (viewModel != null)
            {
                var property = viewModel.ModelXRef.GetExisting(_property) as Model.Entity.NavigationProperty;
                Debug.Assert(property != null);
                DeleteEFElementCommand.DeleteInTransaction(cpc, property);
                viewModel.ModelXRef.Remove(property, _property);
            }
        }
Esempio n. 6
0
 // <summary>
 //     NOTE: The association set mapping view model doesn't keep a reference to the mapping model item. Instead, it
 //     keeps it to the AssociationSet and then it can find the AssociationSetMapping as an anti-dep.  We don't need to clear
 //     or set the ModelItem property.
 // </summary>
 internal override void DeleteModelItem(CommandProcessorContext cpc)
 {
     if (IsModelItemDeleted() == false)
     {
         // create a context if we weren't passed one
         if (cpc == null)
         {
             cpc = new CommandProcessorContext(
                 Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_DeleteAssociationSetMapping);
         }
         DeleteEFElementCommand.DeleteInTransaction(cpc, AssociationSet.AssociationSetMapping);
     }
 }
Esempio n. 7
0
        internal override void Invoke(CommandProcessorContext cpc)
        {
            var viewModel = _association.GetRootViewModel();

            Debug.Assert(viewModel != null, "Unable to find root view model from association: " + _association.Name);

            if (viewModel != null)
            {
                var association = viewModel.ModelXRef.GetExisting(_association) as Model.Entity.Association;
                Debug.Assert(association != null);
                DeleteEFElementCommand.DeleteInTransaction(cpc, association);
                viewModel.ModelXRef.Remove(association, _association);
            }
        }
        private static void SetEndOnDelete(AssociationEnd end, string value)
        {
            var cpc = PropertyWindowViewModelHelper.GetCommandProcessorContext();

            if (end.OnDeleteAction != null &&
                value == ModelConstants.OnDeleteAction_None)
            {
                DeleteEFElementCommand.DeleteInTransaction(cpc, end.OnDeleteAction);
            }
            else if (end.OnDeleteAction == null &&
                     value == ModelConstants.OnDeleteAction_Cascade)
            {
                CommandProcessor.InvokeSingleCommand(cpc, new CreateOnDeleteActionCommand(end, value));
            }
        }
Esempio n. 9
0
        internal override void Invoke(CommandProcessorContext cpc)
        {
            var viewModel = EntityTypeShape.GetRootViewModel();

            Debug.Assert(viewModel != null, "Unable to find root view model from entity type shape: " + EntityTypeShape.AccessibleName);
            if (viewModel != null)
            {
                var modelEntityShape = viewModel.ModelXRef.GetExisting(EntityTypeShape) as Model.Designer.EntityTypeShape;
                if (modelEntityShape != null)
                {
                    DeleteEFElementCommand.DeleteInTransaction(cpc, modelEntityShape);
                    viewModel.ModelXRef.Remove(modelEntityShape, EntityTypeShape);
                }
            }
        }
Esempio n. 10
0
        internal override void Invoke(CommandProcessorContext cpc)
        {
            var viewModel = InheritanceConnector.GetRootViewModel();

            Debug.Assert(viewModel != null, "Unable to find root view model from inheritance connector: " + InheritanceConnector);

            if (viewModel != null)
            {
                var modelInheritanceConnector = viewModel.ModelXRef.GetExisting(InheritanceConnector) as Model.Designer.InheritanceConnector;
                if (modelInheritanceConnector != null)
                {
                    viewModel.ModelXRef.Remove(modelInheritanceConnector, InheritanceConnector);
                    DeleteEFElementCommand.DeleteInTransaction(cpc, modelInheritanceConnector);
                }
            }
        }
 /// <summary>
 ///     Loop through our _itemToDelete list and make the calls to ModelController to
 ///     actually remove the item.
 /// </summary>
 private void CleanUp()
 {
     foreach (var deleteMe in _itemsToDelete)
     {
         var deleteElement = deleteMe as EFElement;
         if (deleteElement != null)
         {
             DeleteEFElementCommand.DeleteInTransaction(_cpc, deleteElement);
         }
         else
         {
             Debug.Fail("We are trying to delete a type that we don't handle");
             deleteMe.Delete();
         }
     }
 }
Esempio n. 12
0
        internal override void Invoke(CommandProcessorContext cpc)
        {
            var viewModel = AssociationConnector.GetRootViewModel();

            Debug.Assert(
                viewModel != null, "Unable to find root view model from association connector: " + AssociationConnector.AccessibleName);

            if (viewModel != null)
            {
                var modelAssociationConnector = viewModel.ModelXRef.GetExisting(AssociationConnector) as Model.Designer.AssociationConnector;
                if (modelAssociationConnector != null)
                {
                    DeleteEFElementCommand.DeleteInTransaction(cpc, modelAssociationConnector);
                    viewModel.ModelXRef.Remove(modelAssociationConnector, AssociationConnector);
                }
            }
        }
Esempio n. 13
0
        internal override void Invoke(CommandProcessorContext cpc)
        {
            var viewModel = EntityType.GetRootViewModel();

            Debug.Assert(viewModel != null, "Unable to find root view model from entity-type:" + EntityType.Name);
            if (viewModel != null)
            {
                var entityType = viewModel.ModelXRef.GetExisting(EntityType) as Model.Entity.EntityType;
                // Escher EntityType can be null.
                // Scenario: When a user adds an entity-type using toolbox, the code in EntityType_AddRule class will delete the DSL EntityType before Model's EntityType is created.
                // In that scenario, the xref between DSL's Entity-Type and Model's Entity-Type has not been established yet.
                if (entityType != null)
                {
                    DeleteEFElementCommand.DeleteInTransaction(cpc, entityType);
                    viewModel.ModelXRef.Remove(entityType, EntityType);
                }
            }
        }
Esempio n. 14
0
        // <summary>
        //     NOTE: We don't call this.Parent.RemoveChild(this) here because this is always called from the MappingEFElement.Delete() method
        //     which will remove this item from the parent.
        // </summary>
        internal override void DeleteModelItem(CommandProcessorContext cpc)
        {
            Debug.Assert(ModelItem != null, "We are trying to delete a null ModelItem");
            if (IsModelItemDeleted() == false)
            {
                if (cpc == null)
                {
                    cpc = new CommandProcessorContext(
                        Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_DeleteResultBinding);
                }

                // use the item's delete command
                var deleteCommand = ResultBinding.GetDeleteCommand();
                deleteCommand.PostInvokeEvent += (o, eventsArgs) => { ModelItem = null; };

                DeleteEFElementCommand.DeleteInTransaction(cpc, deleteCommand);
            }

            // if IsModelItemDeleted == true, just make sure that it is null anyways
            ModelItem = null;
        }
Esempio n. 15
0
        public void Invoke()
        {
            Debug.Assert(_association != null, "The Association reference is null");

            // if the association was deleted in this transaction, just return since we won't need to process it
            if (_association == null ||
                _association.XObject == null)
            {
                return;
            }

            // if foreign keys are supported in this EF version, then we skip all processing here.
            if (EdmFeatureManager.GetForeignKeysInModelFeatureState(_association.Artifact.SchemaVersion).IsEnabled())
            {
                return;
            }

            Debug.Assert(_association.EntityModel.IsCSDL, "Inferring ref constraints isn't valid for SSDL associations");
            Debug.Assert(
                _association.AssociationEnds().Count == 2,
                "The association to be processed does not have 2 ends while trying to infer ref constraints");
            Debug.Assert(
                _association.AssociationSet != null,
                "The association being processed does not have a valid AssociationSet while trying to infer ref constraints");

            // some local aliases for readability
            var end1 = _association.AssociationEnds()[0];
            var end2 = _association.AssociationEnds()[1];

            Debug.Assert(end1 != null && end2 != null, "Null end found while trying to infer ref constraints");
            if (end1 == null ||
                end2 == null)
            {
                return;
            }

            // regardless, we will remove the constraint
            if (_association.ReferentialConstraint != null)
            {
                DeleteEFElementCommand.DeleteInTransaction(_context, _association.ReferentialConstraint);
            }

            // we will never create a constraint against a self-association
            if (end1.Type.Target == end2.Type.Target)
            {
                return;
            }

            AssociationEnd principal = null;
            AssociationEnd dependent = null;

            ModelHelper.DeterminePrincipalDependentAssociationEnds(
                _association, out principal, out dependent,
                ModelHelper.DeterminePrincipalDependentAssociationEndsScenario.InferReferentialConstraint);

            // We found our principal and dependent ends but we still need to confirm that
            // the AssociationSetMapping contains key properties that are mapped to the same column
            if (principal != null &&
                principal.Type.Target != null &&
                dependent != null &&
                dependent.Type.Target != null)
            {
                var associationSet = _association.AssociationSet;
                if (associationSet != null)
                {
                    var asm = associationSet.AssociationSetMapping;
                    if (asm != null &&
                        asm.EndProperties().Count == 2)
                    {
                        // any commonly mapped properties will be loaded into these HashSets
                        var principalPropertyRefs = new HashSet <Property>();
                        var dependentPropertyRefs = new HashSet <Property>();

                        EndProperty dependentEndProperty = null;
                        EndProperty principalEndProperty = null;
                        var         endProp1             = asm.EndProperties()[0];
                        var         endProp2             = asm.EndProperties()[1];
                        if (endProp1.Name.Target != null)
                        {
                            if (endProp1.Name.Target.Role.Target == dependent)
                            {
                                dependentEndProperty = endProp1;
                                principalEndProperty = endProp2;
                            }
                            else
                            {
                                dependentEndProperty = endProp2;
                                principalEndProperty = endProp1;
                            }
                        }

                        Debug.Assert(
                            dependentEndProperty != null && principalEndProperty != null,
                            "Either dependent or principal EndProperty is null");
                        if (dependentEndProperty != null &&
                            principalEndProperty != null)
                        {
                            // for each column that is mapped to a key property on the dependent end, determine if there is a
                            // key property on the principal end that it is also mapped to. If there is, then we need a
                            // ReferentialConstraint
                            foreach (var dependentScalarProp in dependentEndProperty.ScalarProperties())
                            {
                                var principalScalarProp =
                                    principalEndProperty.ScalarProperties()
                                    .FirstOrDefault(psp => psp.ColumnName.Target == dependentScalarProp.ColumnName.Target);
                                if (principalScalarProp != null)
                                {
                                    principalPropertyRefs.Add(principalScalarProp.Name.Target);
                                    dependentPropertyRefs.Add(dependentScalarProp.Name.Target);
                                }
                            }

                            Debug.Assert(
                                principalPropertyRefs.Count == dependentPropertyRefs.Count,
                                "List of keys are mismatched while trying to create a Ref Constraint");
                            if (principalPropertyRefs.Count > 0 &&
                                dependentPropertyRefs.Count > 0 &&
                                principalPropertyRefs.Count == dependentPropertyRefs.Count)
                            {
                                // if the propertyRefs sets have any data in them, add the constraint
                                var cmd = new CreateReferentialConstraintCommand(
                                    principal, dependent, principalPropertyRefs, dependentPropertyRefs);
                                CommandProcessor.InvokeSingleCommand(_context, cmd);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 16
0
        public void Invoke()
        {
            Debug.Assert(_associationSetMapping != null, "The AssociationSetMapping reference is null");

            // if the association set mapping was deleted in this transaction, just return since we won't need to process it
            if (_associationSetMapping == null ||
                _associationSetMapping.XObject == null)
            {
                return;
            }

            var association = _associationSetMapping.TypeName.Target;

            Debug.Assert(association != null, "AssociationSetMapping had an invalid Association reference");
            if (association == null)
            {
                return;
            }

            // if the association was deleted in this transaction, just return since we won't need to process it
            if (association.XObject == null)
            {
                return;
            }

            var ends = association.AssociationEnds();

            Debug.Assert(ends.Count == 2, "AssociationSetMapping's Association does not have 2 ends.");
            if (ends.Count < 2)
            {
                return;
            }

            var end1 = ends[0];
            var end2 = ends[1];

            Debug.Assert(end1 != null && end2 != null, "AssociationSetMapping's Association has an invalid reference to one or more Ends");
            if (end1 == null ||
                end2 == null)
            {
                return;
            }

            var ses = _associationSetMapping.StoreEntitySet.Target;

            Debug.Assert(ses != null, "AssociationSetMapping had an invalid StoreEntitySet reference");
            if (ses == null)
            {
                return;
            }

            // see if we need conditions
            var needsConditionEnd1 = DoesEndNeedCondition(end1, end2, ses.EntityType.Target);
            var needsConditionEnd2 = DoesEndNeedCondition(end2, end1, ses.EntityType.Target);

            // clear out existing conditions
            var existingConditions = new List <Condition>();

            existingConditions.AddRange(_associationSetMapping.Conditions());
            for (var i = existingConditions.Count - 1; i >= 0; i--)
            {
                var condition = existingConditions[i];
                DeleteEFElementCommand.DeleteInTransaction(_cpc, condition);
            }

            if (needsConditionEnd1 || needsConditionEnd2)
            {
                // now see which conditions we need to add, looking at each EndProperty for the AssociationSetMapping
                var conditionCreateForColumn = new HashSet <Property>();
                foreach (var endProperty in _associationSetMapping.EndProperties())
                {
                    if (endProperty.Name.Target != null)
                    {
                        // then look at each mapped ScalarProperty
                        foreach (var sp in endProperty.ScalarProperties())
                        {
                            // if the column mapped is not a key, add a condition (checking for dupes)
                            if (sp.ColumnName.Target != null &&
                                sp.ColumnName.Target.IsKeyProperty == false &&
                                conditionCreateForColumn.Contains(sp.ColumnName.Target) == false)
                            {
                                var createCond = new CreateEndConditionCommand(_associationSetMapping, sp.ColumnName.Target, false, null);
                                CommandProcessor.InvokeSingleCommand(_cpc, createCond);

                                conditionCreateForColumn.Add(sp.ColumnName.Target);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 17
0
        public void Invoke()
        {
            Debug.Assert(_association != null, "The Association reference is null");

            // if the association was deleted in this transaction, just return since we won't need to process it
            if (_association == null ||
                _association.XObject == null)
            {
                return;
            }

            // if foreign keys aren't supported in this EF version, then we skip all processing here.
            if (!EdmFeatureManager.GetForeignKeysInModelFeatureState(_association.Artifact.SchemaVersion).IsEnabled())
            {
                return;
            }

            Debug.Assert(_association.EntityModel.IsCSDL, "Creating foreign key properties isn't valid for SSDL associations");
            Debug.Assert(
                _association.AssociationEnds().Count == 2,
                "The association to be processed does not have 2 ends while trying to create foreign key properties");
            Debug.Assert(
                _association.AssociationSet != null,
                "The association being processed does not have a valid AssociationSet while trying to create foreign key properties");

            // remove any existing RC
            if (_association.ReferentialConstraint != null)
            {
                DeleteEFElementCommand.DeleteInTransaction(_context, _association.ReferentialConstraint);
            }

            // figure out the principal and dependent ends
            AssociationEnd principal = null;
            AssociationEnd dependent = null;

            ModelHelper.DeterminePrincipalDependentAssociationEnds(
                _association, out principal, out dependent,
                ModelHelper.DeterminePrincipalDependentAssociationEndsScenario.CreateForeignKeyProperties);

            if (principal != null &&
                principal.Type.Target != null &&
                dependent != null &&
                dependent.Type.Target != null)
            {
                // many-to-many associations don't need foreign key properties
                if (principal.Multiplicity.Value == ModelConstants.Multiplicity_Many &&
                    dependent.Multiplicity.Value == ModelConstants.Multiplicity_Many)
                {
                    return;
                }

                var principalPropertyRefs = new HashSet <Property>();
                var dependentPropertyRefs = new HashSet <Property>();

                // add properties to the dependent side

                IEnumerable <Property> pkeys;
                var cet = principal.Type.Target as ConceptualEntityType;
                if (cet != null)
                {
                    // the principal is a c-side entity
                    pkeys = cet.ResolvableTopMostBaseType.ResolvableKeys;
                }
                else
                {
                    // the principal is an s-side entity
                    pkeys = principal.Type.Target.ResolvableKeys;
                }

                foreach (var pkey in pkeys)
                {
                    // build up the foreign key name, add an '_' if the resulting name wouldn't be camel-case
                    // e.g.
                    //  Order and Id become "OrderId"
                    //  order and id become "order_id"
                    //
                    // get a unique name for this new property
                    var fkeyName = string.Format(
                        CultureInfo.CurrentCulture, "{0}{1}{2}",
                        principal.Type.Target.LocalName.Value,
                        (char.IsUpper(pkey.LocalName.Value, 0) ? "" : "_"),
                        pkey.LocalName.Value);
                    fkeyName = ModelHelper.GetUniqueName(typeof(Property), dependent.Type.Target, fkeyName);

                    // tweak the properties; we are using the copy/paste process since we have to
                    // copy all facets of the pk and that code does this already
                    var pcf = new PropertyClipboardFormat(pkey);
                    pcf.PropertyName          = fkeyName;
                    pcf.IsKeyProperty         = false;
                    pcf.IsNullable            = (principal.Multiplicity.Value == ModelConstants.Multiplicity_ZeroOrOne ? true : false);
                    pcf.StoreGeneratedPattern = string.Empty;
                    pcf.GetterAccessModifier  = string.Empty;
                    pcf.SetterAccessModifier  = string.Empty;

                    // create the new property
                    var cmd = new CopyPropertyCommand(pcf, dependent.Type.Target);
                    CommandProcessor.InvokeSingleCommand(_context, cmd);
                    var fkey = cmd.Property;

                    // build up our list of keys
                    Debug.Assert(fkey != null, "CreateForeignKeyProperties was not able to create a foreign key");
                    if (fkey != null)
                    {
                        principalPropertyRefs.Add(pkey);
                        dependentPropertyRefs.Add(fkey);
                    }
                }

                // create the new RC
                Debug.Assert(
                    principalPropertyRefs.Count == dependentPropertyRefs.Count,
                    "List of keys are mismatched while trying to create a Ref Constraint");
                if (principalPropertyRefs.Count > 0 &&
                    dependentPropertyRefs.Count > 0 &&
                    principalPropertyRefs.Count == dependentPropertyRefs.Count)
                {
                    var cmd = new CreateReferentialConstraintCommand(principal, dependent, principalPropertyRefs, dependentPropertyRefs);
                    CommandProcessor.InvokeSingleCommand(_context, cmd);
                }
            }
        }