Exemple #1
0
        /// <summary>
        ///     The method will do the following:
        ///     - Creates a complex property with specified typeName in the entity-type.
        ///     - The complex property will be inserted in the specified position.
        ///     - Set the property's facet values.
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="name">The name of the new property</param>
        /// <param name="entityType">The entity to create this property in</param>
        /// <param name="typeName">The complex property name.</param>
        /// <param name="concurrencyMode">The property concurrencyMode facet value.</param>
        /// <param name="getterAccessModifier">The property getterAccessModifier facet value.</param>
        /// <param name="setterAccessModifier">The property setterAccessModifier facet value.</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 static ComplexConceptualProperty CreateComplexProperty(
            CommandProcessorContext cpc, string name, EntityType entityType, string typeName,
            string concurrencyMode, string getterAccessModifier, string setterAccessModifier, InsertPropertyPosition insertPosition)
        {
            var cmd = new CreateComplexPropertyCommand(name, entityType, typeName, insertPosition);

            cmd.PostInvokeEvent += (o, eventsArgs) =>
            {
                var complexProperty = cmd.Property;
                Debug.Assert(complexProperty != null, "We didn't get good property out of the command");
                if (complexProperty != null)
                {
                    // set ComplexProperty attributes
                    if (!String.IsNullOrEmpty(concurrencyMode))
                    {
                        complexProperty.ConcurrencyMode.Value = concurrencyMode;
                    }
                    if (!String.IsNullOrEmpty(getterAccessModifier))
                    {
                        complexProperty.Getter.Value = getterAccessModifier;
                    }
                    if (!String.IsNullOrEmpty(setterAccessModifier))
                    {
                        complexProperty.Setter.Value = setterAccessModifier;
                    }
                }
            };
            var cp = new CommandProcessor(cpc, cmd);

            cp.Invoke();
            return(cmd.Property);
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // first create new ComplexType
            _createdComplexType = CreateComplexTypeCommand.CreateComplexTypeWithDefaultName(cpc);
            // add a copy of Entity properties to the ComplexType
            var copyCmd      = new CopyPropertiesCommand(new PropertiesClipboardFormat(_properties), _createdComplexType);
            var propertyName = ModelHelper.GetUniqueConceptualPropertyName(
                ComplexConceptualProperty.DefaultComplexPropertyName, _entityType);
            // add a new Property of created ComplexType to the Entity
            var createCPCmd = new CreateComplexPropertyCommand(propertyName, _entityType, _createdComplexType);
            var cp          = new CommandProcessor(cpc, copyCmd, createCPCmd);

            cp.Invoke();
            _createdComplexProperty = createCPCmd.Property;

            // preserve mappings
            foreach (var property in _properties)
            {
                if (property is ComplexConceptualProperty)
                {
                    var createdComplexTypeProperty =
                        _createdComplexType.FindPropertyByLocalName(property.LocalName.Value) as ComplexConceptualProperty;
                    Debug.Assert(createdComplexTypeProperty != null, "Copied complex property not found");
                    if (createdComplexTypeProperty != null)
                    {
                        foreach (var complexPropertyMapping in property.GetAntiDependenciesOfType <ComplexProperty>())
                        {
                            PreserveComplexPropertyMapping(cpc, complexPropertyMapping, createdComplexTypeProperty);
                        }

                        foreach (var fcp in property.GetAntiDependenciesOfType <FunctionComplexProperty>())
                        {
                            PreserveFunctionComplexPropertyMapping(cpc, fcp, createdComplexTypeProperty);
                        }
                    }
                }
                else
                {
                    var createdComplexTypeProperty = _createdComplexType.FindPropertyByLocalName(property.LocalName.Value);
                    Debug.Assert(createdComplexTypeProperty != null, "Copied property not found");
                    if (createdComplexTypeProperty != null)
                    {
                        // update EntityTypeMappings
                        foreach (var scalarPropertyMapping in property.GetAntiDependenciesOfType <ScalarProperty>())
                        {
                            PreserveScalarPropertyMapping(cpc, scalarPropertyMapping, createdComplexTypeProperty);
                        }

                        // update ModificationFunctionMappings
                        foreach (var fsp in property.GetAntiDependenciesOfType <FunctionScalarProperty>())
                        {
                            PreserveFunctionScalarPropertyMapping(cpc, fsp, createdComplexTypeProperty);
                        }
                    }
                }
            }
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // first create new ComplexType
            _createdComplexType = CreateComplexTypeCommand.CreateComplexTypeWithDefaultName(cpc);
            // add a copy of Entity properties to the ComplexType
            var copyCmd = new CopyPropertiesCommand(new PropertiesClipboardFormat(_properties), _createdComplexType);
            var propertyName = ModelHelper.GetUniqueConceptualPropertyName(
                ComplexConceptualProperty.DefaultComplexPropertyName, _entityType);
            // add a new Property of created ComplexType to the Entity
            var createCPCmd = new CreateComplexPropertyCommand(propertyName, _entityType, _createdComplexType);
            var cp = new CommandProcessor(cpc, copyCmd, createCPCmd);
            cp.Invoke();
            _createdComplexProperty = createCPCmd.Property;

            // preserve mappings
            foreach (var property in _properties)
            {
                if (property is ComplexConceptualProperty)
                {
                    var createdComplexTypeProperty =
                        _createdComplexType.FindPropertyByLocalName(property.LocalName.Value) as ComplexConceptualProperty;
                    Debug.Assert(createdComplexTypeProperty != null, "Copied complex property not found");
                    if (createdComplexTypeProperty != null)
                    {
                        foreach (var complexPropertyMapping in property.GetAntiDependenciesOfType<ComplexProperty>())
                        {
                            PreserveComplexPropertyMapping(cpc, complexPropertyMapping, createdComplexTypeProperty);
                        }

                        foreach (var fcp in property.GetAntiDependenciesOfType<FunctionComplexProperty>())
                        {
                            PreserveFunctionComplexPropertyMapping(cpc, fcp, createdComplexTypeProperty);
                        }
                    }
                }
                else
                {
                    var createdComplexTypeProperty = _createdComplexType.FindPropertyByLocalName(property.LocalName.Value);
                    Debug.Assert(createdComplexTypeProperty != null, "Copied property not found");
                    if (createdComplexTypeProperty != null)
                    {
                        // update EntityTypeMappings
                        foreach (var scalarPropertyMapping in property.GetAntiDependenciesOfType<ScalarProperty>())
                        {
                            PreserveScalarPropertyMapping(cpc, scalarPropertyMapping, createdComplexTypeProperty);
                        }

                        // update ModificationFunctionMappings
                        foreach (var fsp in property.GetAntiDependenciesOfType<FunctionScalarProperty>())
                        {
                            PreserveFunctionScalarPropertyMapping(cpc, fsp, createdComplexTypeProperty);
                        }
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        ///     Creates a complex property in the passed in entity of the first ComplexType in the model ("Undefined" if there isn't one).
        ///     NOTE: If the cpc already has an active transaction, these changes will be in that transaction
        ///     and the caller of this helper method must commit it to see these changes committed.
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="name">The name of the new property</param>
        /// <param name="entityType">The entity to create this property in</param>
        /// <returns>The new Complex Property</returns>
        internal static ComplexConceptualProperty CreateDefaultProperty(CommandProcessorContext cpc, string name, EntityType entityType)
        {
            var         model = entityType.EntityModel as ConceptualEntityModel;
            ComplexType type  = null;

            foreach (var complexType in model.ComplexTypes())
            {
                type = complexType;
                break;
            }
            var cpcd = new CreateComplexPropertyCommand(name, entityType, type);

            var cp = new CommandProcessor(cpc, cpcd);

            cp.Invoke();

            return(cpcd.Property);
        }
Exemple #5
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            Debug.Assert(_entityType != null || _complexType != null, "Undefined parent type");

            if (_entityType != null)
            {
                var propertyName = ModelHelper.GetUniqueConceptualPropertyName(_clipboardProperty.PropertyName, _entityType);

                if (_clipboardProperty.IsComplexProperty)
                {
                    _createdProperty = CreateComplexPropertyCommand.CreateComplexProperty(
                        cpc, propertyName, _entityType, _clipboardProperty.PropertyType,
                        _clipboardProperty.ConcurrencyMode, _clipboardProperty.GetterAccessModifier, _clipboardProperty.SetterAccessModifier,
                        _insertPosition);
                }
                else if (_clipboardProperty.IsConceptualProperty)
                {
                    Debug.Assert(_entityType.EntityModel.IsCSDL, "This should be a c-side Entity");
                    if (_entityType.EntityModel.IsCSDL)
                    {
                        _createdProperty = CreatePropertyCommand.CreateConceptualProperty(
                            cpc, propertyName, _entityType as ConceptualEntityType, _clipboardProperty.PropertyType,
                            _clipboardProperty.IsNullable,
                            _clipboardProperty.Default, _clipboardProperty.ConcurrencyMode, _clipboardProperty.GetterAccessModifier,
                            _clipboardProperty.SetterAccessModifier,
                            _clipboardProperty.MaxLength, _clipboardProperty.FixedLength, _clipboardProperty.Precision,
                            _clipboardProperty.Scale, _clipboardProperty.Unicode, _clipboardProperty.Collation,
                            _clipboardProperty.StoreGeneratedPattern, _insertPosition);
                    }
                }
                else
                {
                    Debug.Assert(_entityType.EntityModel.IsCSDL == false, "This should be a s-side Entity");
                    if (!_entityType.EntityModel.IsCSDL)
                    {
                        _createdProperty = CreatePropertyCommand.CreateStorageProperty(
                            cpc, propertyName, _entityType as StorageEntityType, _clipboardProperty.PropertyType,
                            _clipboardProperty.IsNullable,
                            _clipboardProperty.Default, _clipboardProperty.MaxLength,
                            DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.FixedLength), _clipboardProperty.Precision,
                            _clipboardProperty.Scale,
                            DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.Unicode), _clipboardProperty.Collation,
                            _clipboardProperty.ConcurrencyMode);
                    }
                }

                if (_clipboardProperty.IsKeyProperty)
                {
                    var setKey = new SetKeyPropertyCommand(_createdProperty, true);
                    CommandProcessor.InvokeSingleCommand(cpc, setKey);
                }

                AddAnnotations(_clipboardProperty, _createdProperty);
            }
            else
            {
                var cmd = new CopyComplexTypePropertyCommand(_clipboardProperty, _complexType);
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
                _createdProperty = cmd.Property;
            }
        }
 /// <summary>
 ///     The method will do the following:
 ///     - Creates a complex property with specified typeName in the entity-type.
 ///     - The complex property will be inserted in the specified position.
 ///     - Set the property's facet values.
 /// </summary>
 /// <param name="cpc"></param>
 /// <param name="name">The name of the new property</param>
 /// <param name="entityType">The entity to create this property in</param>
 /// <param name="typeName">The complex property name.</param>
 /// <param name="concurrencyMode">The property concurrencyMode facet value.</param>
 /// <param name="getterAccessModifier">The property getterAccessModifier facet value.</param>
 /// <param name="setterAccessModifier">The property setterAccessModifier facet value.</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 static ComplexConceptualProperty CreateComplexProperty(
     CommandProcessorContext cpc, string name, EntityType entityType, string typeName,
     string concurrencyMode, string getterAccessModifier, string setterAccessModifier, InsertPropertyPosition insertPosition)
 {
     var cmd = new CreateComplexPropertyCommand(name, entityType, typeName, insertPosition);
     cmd.PostInvokeEvent += (o, eventsArgs) =>
         {
             var complexProperty = cmd.Property;
             Debug.Assert(complexProperty != null, "We didn't get good property out of the command");
             if (complexProperty != null)
             {
                 // set ComplexProperty attributes
                 if (!String.IsNullOrEmpty(concurrencyMode))
                 {
                     complexProperty.ConcurrencyMode.Value = concurrencyMode;
                 }
                 if (!String.IsNullOrEmpty(getterAccessModifier))
                 {
                     complexProperty.Getter.Value = getterAccessModifier;
                 }
                 if (!String.IsNullOrEmpty(setterAccessModifier))
                 {
                     complexProperty.Setter.Value = setterAccessModifier;
                 }
             }
         };
     var cp = new CommandProcessor(cpc, cmd);
     cp.Invoke();
     return cmd.Property;
 }
        /// <summary>
        ///     Creates a complex property in the passed in entity of the first ComplexType in the model ("Undefined" if there isn't one).
        ///     NOTE: If the cpc already has an active transaction, these changes will be in that transaction
        ///     and the caller of this helper method must commit it to see these changes committed.
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="name">The name of the new property</param>
        /// <param name="entityType">The entity to create this property in</param>
        /// <returns>The new Complex Property</returns>
        internal static ComplexConceptualProperty CreateDefaultProperty(CommandProcessorContext cpc, string name, EntityType entityType)
        {
            var model = entityType.EntityModel as ConceptualEntityModel;
            ComplexType type = null;
            foreach (var complexType in model.ComplexTypes())
            {
                type = complexType;
                break;
            }
            var cpcd = new CreateComplexPropertyCommand(name, entityType, type);

            var cp = new CommandProcessor(cpc, cpcd);
            cp.Invoke();

            return cpcd.Property;
        }