/// <summary>
        ///     Deletes the passed in EntityType
        /// </summary>
        /// <param name="entityType"></param>
        internal DeleteEntityTypeCommand(EntityType entityType)
            : base(entityType)
        {
            CommandValidation.ValidateEntityType(entityType);

            SaveDeletedInformation();
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            if (_diagram != null)
            {
                // Add diagram id information in the transaction context.
                // This is to ensure the diagram objects are created correctly.
                if (cpc.EfiTransaction.GetContextValue<DiagramContextItem>(EfiTransactionOriginator.TransactionOriginatorDiagramId) == null)
                {
                    cpc.EfiTransaction.AddContextValue(
                        EfiTransactionOriginator.TransactionOriginatorDiagramId, new DiagramContextItem(_diagram.Id.Value));
                }
            }

            var service = cpc.EditingContext.GetEFArtifactService();
            var artifact = service.Artifact;

            // check if entity is in the model
            _createdEntity = artifact.ArtifactSet.LookupSymbol(_clipboardEntity.NormalizedName) as EntityType;
            if (_diagram != null
                && _createdEntity != null
                && _createdEntity is ConceptualEntityType)
            {
                if (_createdEntity.GetAntiDependenciesOfType<EntityTypeShape>().Count(ets => ets.Diagram.Id == _diagram.Id.Value) == 0)
                {
                    // CreateEntityTypeShapeAndConnectorsInDiagram method will check if the shape for the entity-type has been created; 
                    // and it will not create one if the shape already exists in the diagram.
                    // Also, VerifyDiagramModelIntegrityVisitor will assert if there are duplicate diagram shapes (shapes that point to the same model element)
                    // every-time a command transaction is committed. So adding another check to do the same thing here is redundant.
                    CreateEntityTypeShapeCommand.CreateEntityTypeShapeAndConnectorsInDiagram(
                        cpc, _diagram, _createdEntity as ConceptualEntityType, _clipboardEntity.EntityTypeShapeFillColor, false);
                    return;
                }
            }
            CreateEntityCopyInModel(cpc);
        }
 public MappingFunctionEntityType(EditingContext context, EntityType entityType, MappingEFElement parent)
     : base(context, entityType, parent)
 {
     _insertMapping = new MappingModificationFunctionMapping(context, null, this, ModificationFunctionType.Insert);
     _updateMapping = new MappingModificationFunctionMapping(context, null, this, ModificationFunctionType.Update);
     _deleteMapping = new MappingModificationFunctionMapping(context, null, this, ModificationFunctionType.Delete);
 }
 /// <summary>
 ///     Creates a copy of a collection of Properties from clipboard format in the EntityType
 /// </summary>
 internal CopyPropertiesCommand(
     PropertiesClipboardFormat clipboardProperties, EntityType entity, InsertPropertyPosition insertPosition)
 {
     _clipboardProperties = clipboardProperties;
     _entity = entity;
     _insertPosition = insertPosition;
     _properties = null;
 }
        internal CreateComplexTypeFromPropertiesCommand(EntityType entityType, List<Property> properties)
        {
            CommandValidation.ValidateConceptualEntityType(entityType);
            Debug.Assert(properties.Count > 0, "No properties to copy");

            _entityType = entityType;
            _properties = properties;
        }
        internal CreateInheritanceConnectorCommand(Diagram diagram, EntityType entity)
        {
            CommandValidation.ValidateConceptualEntityType(entity);
            Debug.Assert(diagram != null, "diagram is null");

            _diagram = diagram;
            _entity = entity;
        }
        /// <summary>
        ///     Creates new EntityTypeMapping inside specified FunctionImportMapping
        /// </summary>
        /// <param name="functionImportMapping"></param>
        /// <param name="entityType"></param>
        internal CreateFunctionImportTypeMappingCommand(FunctionImportMapping functionImportMapping, EntityType entityType)
            : base(PrereqId)
        {
            CommandValidation.ValidateFunctionImportMapping(functionImportMapping);
            CommandValidation.ValidateEntityType(entityType);

            _functionImportMapping = functionImportMapping;
            _entityType = entityType;
        }
        internal EntityTypeClipboardFormat(EntityType entity)
            : base(entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            _entityName = entity.LocalName.Value;
            var entitySet = entity.EntitySet;

            _navigationProperties = new List<NavigationPropertyClipboardFormat>();

            var cet = entity as ConceptualEntityType;
            if (cet != null)
            {
                // c-side entity type
                // don't use base type EntitySet name
                if (cet.HasResolvableBaseType
                    || entitySet == null)
                {
                    _entitySetName = ModelHelper.ConstructProposedEntitySetName(entity.Artifact, _entityName);
                }
                else
                {
                    _entitySetName = entitySet.LocalName.Value;
                }
                // Sort the navigation-properties based on navigation-properties' XElement orders.
                // This is so that we can create the copy of navigation-properties in that order.
                foreach (var navigationProperty in ModelHelper.GetListOfPropertiesInTheirXElementsOrder(cet.NavigationProperties().ToList())
                    )
                {
                    _navigationProperties.Add(new NavigationPropertyClipboardFormat(navigationProperty));
                }
            }
            else
            {
                // s-side entity type

                // don't use base type EntitySet name
                if (entitySet == null)
                {
                    _entitySetName = ModelHelper.ConstructProposedEntitySetName(entity.Artifact, _entityName);
                }
                else
                {
                    _entitySetName = entitySet.LocalName.Value;
                }
            }

            _properties = new List<PropertyClipboardFormat>();
            // Sort the properties based on properties's XElement order. This is that so we can create the copy of properties in that order.
            foreach (var property in ModelHelper.GetListOfPropertiesInTheirXElementsOrder(entity.Properties().ToList()))
            {
                _properties.Add(new PropertyClipboardFormat(property));
            }
        }
        /// <summary>
        ///     Creates an EntitySet of the passed in EntityType in either the conceptual or the storage model.
        /// </summary>
        /// <param name="name">The name to use for this set</param>
        /// <param name="entityType">The EntityType that this set will contain</param>
        /// <param name="modelSpace">Either Conceptual or Storage</param>
        /// <param name="uniquifyName">Flag whether the name should be checked for uniqueness and then changed as required</param>
        internal CreateEntitySetCommand(string name, EntityType entityType, ModelSpace modelSpace, bool uniquifyName)
        {
            CommandValidation.ValidateEntityType(entityType);
            ValidateString(name);

            Name = name;
            EntityType = entityType;
            ModelSpaceValue = modelSpace;
            UniquifyName = uniquifyName;
        }
        internal CreateEntityTypeShapeCommand(Diagram diagram, EntityType entity, Color fillColor)
        {
            CommandValidation.ValidateConceptualEntityType(entity);
            Debug.Assert(diagram != null, "diagram is null");

            _diagram = diagram;
            _entity = entity;
            _created = null;
            _fillColor = fillColor;
        }
        internal CreateFragmentScalarPropertyTreeCommand(EntityType conceptualEntityType, List<Property> properties, Property tableColumn)
        {
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);
            CommandValidation.ValidateTableColumn(tableColumn);
            Debug.Assert(properties.Count > 0, "Properties list should contain at least one element");

            _conceptualEntityType = conceptualEntityType;
            _properties = properties;
            _tableColumn = tableColumn;
            _mode = Mode.EntityType;
        }
        /// <summary>
        ///     Creates a Condition based on the column passed in.
        ///     Valid combinations are:
        ///     1. Send true or false for isNull, and null for conditionValue
        ///     2. Send null for isNull, and a non-empty string for conditionValue
        ///     3. Send null for isNull, and null for conditionValue
        ///     You cannot send non-null values to both arguments.
        /// </summary>
        /// <param name="conceptualEntityType"></param>
        /// <param name="tableColumn"></param>
        /// <param name="isNull"></param>
        /// <param name="conditionValue"></param>
        internal CreateFragmentConditionCommand(EntityType conceptualEntityType, Property tableColumn, bool? isNull, string conditionValue)
        {
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);
            CommandValidation.ValidateTableColumn(tableColumn);

            ConceptualEntityType = conceptualEntityType;
            StorageProperty = tableColumn;
            IsNull = isNull;
            ConditionValue = conditionValue;
            Mode = ModeValues.EntityType;
        }
        internal CreateAssociationSetMappingCommand(Association association, EntityType storageEntityType)
            : base(PrereqId)
        {
            CommandValidation.ValidateAssociation(association);
            CommandValidation.ValidateStorageEntityType(storageEntityType);

            EntityContainerMapping = association.Artifact.MappingModel().FirstEntityContainerMapping;
            AssociationSet = association.AssociationSet;
            Association = association;
            StorageEntitySet = storageEntityType.EntitySet as StorageEntitySet;
        }
 internal CreateStorageAssociationCommand(
     string name, EntityType fkTable, EntityType pkTable, bool doesFkFormPk, bool isNullableFk, bool uniquifyNames)
     : base(PrereqId)
 {
     Name = name;
     FkTable = fkTable;
     PkTable = pkTable;
     DoesFkFormPk = doesFkFormPk;
     IsNullableFk = isNullableFk;
     UniquifyNames = uniquifyNames;
 }
        /// <summary>
        ///     Creates a ScalarProperty in a MappingFragment based on the two ends passed in.  This ScalarProperty
        ///     will always be created in the IsTypeOf ETM (key columns are also added to the Default ETM).
        /// </summary>
        /// <param name="conceptualEntityType">A C side entity</param>
        /// <param name="property">This must be a valid Property from the C-Model.</param>
        /// <param name="tableColumn">This must be a valid Property from the S-Model.</param>
        internal CreateFragmentScalarPropertyCommand(EntityType conceptualEntityType, Property property, Property tableColumn)
        {
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);
            CommandValidation.ValidateConceptualProperty(property);
            CommandValidation.ValidateTableColumn(tableColumn);

            ConceptualEntityType = conceptualEntityType;
            Property = property;
            TableColumn = tableColumn;
            ModeValue = Mode.EntityType;
        }
        /// <summary>
        ///     Creates a function mapping element for the passed in Function, inside an EntityTypeMapping
        ///     for the passed in entity.
        /// </summary>
        /// <param name="conceptualEntityType"></param>
        /// <param name="function"></param>
        /// <param name="rowsAffectedParameter">Optional string argument</param>
        /// <param name="type"></param>
        internal CreateFunctionMappingCommand(
            EntityType conceptualEntityType, Function function, Parameter rowsAffectedParameter, ModificationFunctionType type)
        {
            Debug.Assert(type != ModificationFunctionType.None, "You cannot pass the None type");
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);
            CommandValidation.ValidateFunction(function);

            _conceptualEntityType = conceptualEntityType;
            _function = function;
            _type = type;
            _rowsAffectedParameter = rowsAffectedParameter;
        }
        /// <summary>
        ///     Create MappingFragment for the passed in ConceptualEntityType and StoreEntityType, and inside the
        ///     ETM based on the passed in kind.
        /// </summary>
        /// <param name="conceptualEntityType">This must be a valid EntityType from the C-Model.</param>
        /// <param name="storeEntityType">This must be a valid EntityType from the S-Model.</param>
        /// <param name="kind">Specify whether this should be put in an IsTypeOf or Default ETM</param>
        internal CreateMappingFragmentCommand(EntityType conceptualEntityType, EntityType storeEntityType, EntityTypeMappingKind kind)
        {
            CommandValidation.ValidateStorageEntityType(storeEntityType);
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);

            ConceptualEntityType = conceptualEntityType;
            _entityTypeMappingKind = kind;
            _entityTypeMapping = null;
            StorageEntitySet = storeEntityType.EntitySet as StorageEntitySet;

            CommandValidation.ValidateStorageEntitySet(StorageEntitySet);
        }
        /// <summary>
        ///     Creates a ComplexProperty in a MappingFragment based on conceptualEntityType passed in.
        /// </summary>
        /// <param name="conceptualEntityType">A C side entity</param>
        /// <param name="property">This must be a valid Property from the C-Model.</param>
        /// <param name="tableColumn">This must be a valid Property from the S-Model.</param>
        internal CreateFragmentComplexPropertyCommand(
            EntityType conceptualEntityType, ComplexConceptualProperty property, Property tableColumn)
            : base(PrereqId)
        {
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);
            CommandValidation.ValidateConceptualProperty(property);
            CommandValidation.ValidateTableColumn(tableColumn);

            _conceptualEntityType = conceptualEntityType;
            _property = property;
            _tableColumn = tableColumn;
            _mode = Mode.EntityType;
        }
        /// <summary>
        ///     Creates a ResultBinding element that maps the passed in Property to the result column, inside
        ///     an EntityTypeMapping for the passed in entity.  The Function is used to locate the correct
        ///     ModificationFunction to house this.
        /// </summary>
        /// <param name="conceptualEntityType"></param>
        /// <param name="function"></param>
        /// <param name="entityProperty">Optional</param>
        /// <param name="columnName">Optional</param>
        internal CreateResultBindingCommand(
            EntityType conceptualEntityType, Function function, ModificationFunctionType functionType, Property entityProperty,
            string columnName)
        {
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);
            CommandValidation.ValidateFunction(function);
            Debug.Assert(functionType != ModificationFunctionType.None, "You cannot pass the None type");

            _conceptualEntityType = conceptualEntityType;
            _function = function;
            _functionType = functionType;
            _entityProperty = entityProperty;
            _columnName = columnName;
        }
        /// <summary>
        ///     Creates a property in the passed in entity.
        /// </summary>
        /// <param name="name">The name of the new property</param>
        /// <param name="entityType">The entity to create the property in</param>
        /// <param name="type">The type of the property</param>
        /// <param name="nullable">Flag whether the property is nullable or not</param>
        internal CreatePropertyCommand(
            string name, EntityType entityType, string type, bool? nullable, InsertPropertyPosition insertPosition)
            : base(PrereqId)
        {
            ValidateString(name);
            CommandValidation.ValidateEntityType(entityType);
            ValidateString(type);

            Name = name;
            EntityType = entityType;
            Type = type;
            Nullable = nullable;
            _insertPosition = insertPosition;
        }
        /// <summary>
        ///     Creates a ComplexProperty in the given MappingFragment.
        /// </summary>
        /// <param name="mappingFragment">The MappingFragment to place this ComplexProperty; cannot be null.</param>
        /// <param name="property">This must be a valid ComplexTypeProperty.</param>
        /// <param name="isPartial"></param>
        internal CreateFragmentComplexPropertyCommand(MappingFragment mappingFragment, ComplexConceptualProperty property)
            : base(PrereqId)
        {
            CommandValidation.ValidateMappingFragment(mappingFragment);
            CommandValidation.ValidateConceptualProperty(property);

            _mappingFragment = mappingFragment;
            if (mappingFragment != null
                && mappingFragment.EntityTypeMapping != null)
            {
                _conceptualEntityType = mappingFragment.EntityTypeMapping.FirstBoundConceptualEntityType;
            }
            _property = property;
            _mode = Mode.MappingFragment;
        }
        /// <summary>
        ///     Creates a copy of Property from a Clipboard format in the specified EntityType and Position.
        /// </summary>
        /// <param name="entityType">The entity to create the property in</param>
        /// <param name="clipboardProperty"></param>
        /// <param name="insertPosition">Information where the property should be inserted to. If the parameter is null, the property will be placed as the last property of the entity.</param>
        /// <returns></returns>
        internal CopyPropertyCommand(PropertyClipboardFormat clipboardProperty, EntityType entity, InsertPropertyPosition insertPosition)
        {
            if (_insertPosition != null)
            {
                Debug.Assert(
                    entity.EntityModel.IsCSDL, "You can only set insertPosition parameter if the EntityType is a ConceptualEntityType.");
                Debug.Assert(
                    insertPosition.InsertAtProperty != null && insertPosition.InsertAtProperty.EntityType == entity,
                    "Could not create complex property in the given insertPosition because insertPosition's Entity-Type is not the same as the entity-type which the property will be created in.");
            }

            CommandValidation.ValidateEntityType(entity);
            _clipboardProperty = clipboardProperty;
            _entityType = entity;
            _insertPosition = insertPosition;
        }
        internal CreateFragmentScalarPropertyTreeCommand(MappingFragment mappingFragment, List<Property> properties, Property tableColumn)
        {
            CommandValidation.ValidateMappingFragment(mappingFragment);
            CommandValidation.ValidateTableColumn(tableColumn);
            Debug.Assert(properties.Count > 0, "Properties list should contain at least one element");

            _mappingFragment = mappingFragment;
            if (mappingFragment != null
                && mappingFragment.EntityTypeMapping != null)
            {
                _conceptualEntityType = mappingFragment.EntityTypeMapping.FirstBoundConceptualEntityType;
            }
            _properties = properties;
            _tableColumn = tableColumn;
            _mode = Mode.MappingFragment;
        }
        /// <summary>
        ///     Creates a ComplexProperty in the specified position in the entity.
        /// </summary>
        /// <param name="name">The name of the new property</param>
        /// <param name="entityType">The entity to create the property in</param>
        /// <param name="typeName">String representing the type of the property (needs to be a ref name to a ComplexType)</param>
        /// <param name="insertPosition">Information where the property should be inserted to. If the parameter is null, the property will be placed as the last property of the entity.</param>
        internal CreateComplexPropertyCommand(string name, EntityType entityType, string typeName, InsertPropertyPosition insertPosition)
        {
            if (insertPosition != null)
            {
                Debug.Assert(
                    insertPosition.InsertAtProperty != null && insertPosition.InsertAtProperty.EntityType == entityType,
                    "Could not create complex property in the given insertPosition because insertPosition's Entity-Type is not the same as the entity-type which the property will be created in.");
            }

            ValidateString(name);
            CommandValidation.ValidateEntityType(entityType);

            Name = name;
            EntityType = entityType;
            _typeName = typeName;
            _insertPosition = insertPosition;
        }
        /// <summary>
        ///     Delete a function mapping.  The function mapping is located using the passed in EntityType to validate
        ///     the EntityTypeMapping and then the Function to locate the mapping itself.
        /// </summary>
        /// <param name="conceptualEntityType"></param>
        /// <param name="function"></param>
        /// <param name="type"></param>
        internal DeleteFunctionMappingCommand(EntityType conceptualEntityType, Function function, ModificationFunctionType type)
            : base((EFElement)null)
        {
            CommandValidation.ValidateConceptualEntityType(conceptualEntityType);
            CommandValidation.ValidateFunction(function);

            foreach (var mf in function.GetAntiDependenciesOfType<ModificationFunction>())
            {
                if (mf.ModificationFunctionMapping.EntityTypeMapping.FirstBoundConceptualEntityType == conceptualEntityType
                    && mf.FunctionType == type)
                {
                    EFElement = mf;
                    break;
                }
            }

            // don't throw now in the c'tor
            Debug.Assert(ModificationFunction != null, "Couldn't find the ModificationFunction needed to complete this operation");
        }
        private void AddDbObjToEntityTypeNameMap(DatabaseObject key, EntityType et)
        {
            var normalizedName = et.NormalizedName;
            if (normalizedName == null)
            {
                Debug.Fail("null or empty Normalized Name for " + et.ToPrettyString());
                return;
            }

            HashSet<Symbol> entityTypeNamesHashSet = null;
            _databaseObjectToCEntityTypeNamesMap.TryGetValue(key, out entityTypeNamesHashSet);
            if (null == entityTypeNamesHashSet)
            {
                entityTypeNamesHashSet = _databaseObjectToCEntityTypeNamesMap[key] = new HashSet<Symbol>();
            }

            entityTypeNamesHashSet.Add(normalizedName);
        }
        private void AddCEntityTypeNameToEntityTypeIdentityMapping(
            EntityType key, DatabaseObject dbObj)
        {
            var normalizedName = key.NormalizedName;
            if (normalizedName == null)
            {
                Debug.Fail("null or empty Normalized Name for " + key.ToPrettyString());
                return;
            }

            EntityTypeIdentity etId = null;
            _cEntityTypeNameToEntityTypeIdentity.TryGetValue(normalizedName, out etId);
            if (null == etId)
            {
                etId = _cEntityTypeNameToEntityTypeIdentity[normalizedName] = new EntityTypeIdentity();
            }

            etId.AddTableOrView(dbObj);
        }
        internal EntityTypeIdentity GetEntityTypeIdentityForEntityType(EntityType et)
        {
            var normalizedName = et.NormalizedName;
            if (normalizedName == null)
            {
                Debug.Fail("null or empty Normalized Name for " + et.ToPrettyString());
                return null;
            }

            EntityTypeIdentity results;
            _cEntityTypeNameToEntityTypeIdentity.TryGetValue(normalizedName, out results);
            return results;
        }
Example #29
0
        /// <summary>
        ///     Gets the AssociationEnd that is not pointing to the given EntityType. This method should not be
        ///     called for self-associations.
        /// </summary>
        /// <param name="oneEnd"></param>
        /// <returns></returns>
        internal AssociationEnd GetOtherEnd(EntityType entityType)
        {
            Debug.Assert(
                !IsSelfAssociation,
                "GetOtherEnd() will not work correctly for self associations as both ends point to the same entity type");

            AssociationEnd otherEnd = null;
            if (End1.Type.Target == entityType)
            {
                otherEnd = End2;
            }
            else if (End2.Type.Target == entityType)
            {
                otherEnd = End1;
            }

            return otherEnd;
        }
Example #30
0
 /// <summary>
 ///     Get all associations which the entity type participates in.
 /// </summary>
 /// <param name="entityType"></param>
 /// <returns></returns>
 internal static HashSet<Association> GetAssociationsForEntityType(EntityType entityType)
 {
     // Add association connectors
     var participatingAssociations = new HashSet<Association>();
     // First we find all the associations which the entitytype participates.
     foreach (var associationEnd in entityType.GetAntiDependenciesOfType<AssociationEnd>())
     {
         var association = associationEnd.Parent as Association;
         if (association != null
             && participatingAssociations.Contains(association) == false)
         {
             participatingAssociations.Add(association);
         }
     }
     return participatingAssociations;
 }