/// <summary>
        ///     This helper function is an easy way to get a new entity type, entity set and key property in the
        ///     new entity type created in the conceptual or storage model.
        ///     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 commited.
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="name">The name of the new entity</param>
        /// <param name="setName">The name of the new set</param>
        /// <param name="createKeyProperty">A flag whether to create a new key property or not (sending false creates no new property)</param>
        /// <param name="propertyName">The name of the new property</param>
        /// <param name="propertyType">The type of the new property</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>
        /// <param name="isDefaultName">Flag whether the name is the default for new entity types/sets</param>
        /// <returns>The new EntityType</returns>
        internal static EntityType CreateEntityTypeAndEntitySetAndProperty(
            CommandProcessorContext cpc,
            string name, string setName, bool createKeyProperty, string propertyName,
            string propertyType, string propertyStoreGeneratedPattern, ModelSpace modelSpace, bool uniquifyNames, bool isDefaultName = false)
        {
            var cp = new CommandProcessor(cpc);

            var cet = new CreateEntityTypeCommand(name, modelSpace, uniquifyNames);

            cet.CreateWithDefaultName = isDefaultName;
            cp.EnqueueCommand(cet);

            var ces = new CreateEntitySetCommand(setName, cet, modelSpace, uniquifyNames);

            cp.EnqueueCommand(ces);

            if (createKeyProperty)
            {
                var cpcd = new CreatePropertyCommand(propertyName, cet, propertyType, false);
                cpcd.IsIdProperty = true;
                cp.EnqueueCommand(cpcd);

                var skpc = new SetKeyPropertyCommand(cpcd, true);
                cp.EnqueueCommand(skpc);

                var ssgpc = new SetStoreGeneratedPatternCommand(cpcd, propertyStoreGeneratedPattern);
                cp.EnqueueCommand(ssgpc);
            }

            cp.Invoke();

            return(cet.EntityType);
        }
示例#2
0
        /// <summary>
        ///     Sets annotations on the property being created by the passed in command.
        /// </summary>
        /// <param name="prereq">Must be non-null command creating the conceptual property</param>
        /// <param name="storeGeneratedPattern">Optional annotation</param>
        internal SetConceptualPropertyAnnotationsCommand(CreatePropertyCommand prereq, string storeGeneratedPattern)
        {
            ValidatePrereqCommand(prereq);

            _storeGeneratedPattern = storeGeneratedPattern;

            AddPreReqCommand(prereq);
        }
        /// <summary>
        ///     Used to set the StoreGeneratedPattern property on a new property.
        /// </summary>
        /// <param name="prereq">Must be a non-null command creating the property</param>
        /// <param name="isKey">Flag whether to make the property a key or not</param>
        internal SetStoreGeneratedPatternCommand(CreatePropertyCommand prereq, string value)
        {
            ValidatePrereqCommand(prereq);

            SgpValue = value;

            AddPreReqCommand(prereq);
        }
        /// <summary>
        ///     Used to set the StoreGeneratedPattern property on a new property.
        /// </summary>
        /// <param name="prereq">Must be a non-null command creating the property</param>
        /// <param name="isKey">Flag whether to make the property a key or not</param>
        internal SetStoreGeneratedPatternCommand(CreatePropertyCommand prereq, string value)
        {
            ValidatePrereqCommand(prereq);

            SgpValue = value;

            AddPreReqCommand(prereq);
        }
        /// <summary>
        ///     Sets annotations on the property being created by the passed in command.
        /// </summary>
        /// <param name="prereq">Must be non-null command creating the conceptual property</param>
        /// <param name="storeGeneratedPattern">Optional annotation</param>
        internal SetConceptualPropertyAnnotationsCommand(CreatePropertyCommand prereq, string storeGeneratedPattern)
        {
            ValidatePrereqCommand(prereq);

            _storeGeneratedPattern = storeGeneratedPattern;

            AddPreReqCommand(prereq);
        }
 /// <summary>
 ///     Sets facets on the property being created by the passed in command.
 /// </summary>
 /// <param name="prereq">Must be non-null command creating the conceptual property</param>
 /// <param name="theDefault">Optional facet</param>
 /// <param name="concurrencyMode">Optional facet</param>
 /// <param name="getterAccessModifier">Optional facet</param>
 /// <param name="setterAccessModifier">Optional facet</param>
 internal SetConceptualPropertyFacetsCommand(
     CreatePropertyCommand prereq, StringOrNone theDefault, string concurrencyMode, string getterAccessModifier,
     string setterAccessModifier, StringOrPrimitive <UInt32> maxLength, BoolOrNone fixedLength, StringOrPrimitive <UInt32> precision,
     StringOrPrimitive <UInt32> scale, BoolOrNone unicode, StringOrNone collation)
     : base(prereq, theDefault, maxLength, fixedLength, precision, scale, unicode, collation, concurrencyMode)
 {
     _getterAccessModifier = getterAccessModifier;
     _setterAccessModifier = setterAccessModifier;
 }
        /// <summary>
        ///     Used to set a new property as the key.
        /// </summary>
        /// <param name="prereq">Must be a non-null command creating the property</param>
        /// <param name="isKey">Flag whether to make the property a key or not</param>
        internal SetKeyPropertyCommand(CreatePropertyCommand prereq, bool isKey)
        {
            ValidatePrereqCommand(prereq);

            IsKey = isKey;
            _deletePrincipalRCRefs = true;

            AddPreReqCommand(prereq);
        }
 /// <summary>
 ///     Sets facets on the property being created by the passed in command.
 /// </summary>
 /// <param name="prereq">Must be non-null command creating the conceptual property</param>
 /// <param name="theDefault">Optional facet</param>
 /// <param name="concurrencyMode">Optional facet</param>
 /// <param name="getterAccessModifier">Optional facet</param>
 /// <param name="setterAccessModifier">Optional facet</param>
 internal SetConceptualPropertyFacetsCommand(
     CreatePropertyCommand prereq, StringOrNone theDefault, string concurrencyMode, string getterAccessModifier,
     string setterAccessModifier, StringOrPrimitive<UInt32> maxLength, BoolOrNone fixedLength, StringOrPrimitive<UInt32> precision,
     StringOrPrimitive<UInt32> scale, BoolOrNone unicode, StringOrNone collation)
     : base(prereq, theDefault, maxLength, fixedLength, precision, scale, unicode, collation, concurrencyMode)
 {
     _getterAccessModifier = getterAccessModifier;
     _setterAccessModifier = setterAccessModifier;
 }
示例#9
0
        /// <summary>
        ///     Used to set a new property as the key.
        /// </summary>
        /// <param name="prereq">Must be a non-null command creating the property</param>
        /// <param name="isKey">Flag whether to make the property a key or not</param>
        internal SetKeyPropertyCommand(CreatePropertyCommand prereq, bool isKey)
        {
            ValidatePrereqCommand(prereq);

            IsKey = isKey;
            _deletePrincipalRCRefs = true;

            AddPreReqCommand(prereq);
        }
        /// <summary>
        ///     Creates a property in the passed in entity of the default Type (non-nullable String).
        ///     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 commited.
        /// </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 Property</returns>
        internal static Property CreateDefaultProperty(CommandProcessorContext cpc, string name, EntityType entityType)
        {
            var cpcd = new CreatePropertyCommand(
                name, entityType, ModelConstants.DefaultPropertyType, ModelConstants.DefaultPropertyNullability);

            cpcd._createWithDefaultName = true;

            var cp = new CommandProcessor(cpc, cpcd);

            cp.Invoke();

            return(cpcd.CreatedProperty);
        }
        /// <summary>
        ///     Sets facets on the property being created by the passed in command.
        /// </summary>
        /// <param name="prereq">Must be non-null command creating the storage property</param>
        /// <param name="theDefault">Optional facet</param>
        /// <param name="maxLength">Optional facet</param>
        /// <param name="fixedLength">Optional facet</param>
        /// <param name="precision">Optional facet</param>
        /// <param name="scale">Optional facet</param>
        /// <param name="unicode">Optional facet</param>
        /// <param name="collation">Optional facet</param>
        /// <param name="concurrencyMode">Optional facet</param>
        internal SetPropertyFacetsCommand(
            CreatePropertyCommand prereq, StringOrNone theDefault,
            StringOrPrimitive<UInt32> maxLength, BoolOrNone fixedLength, StringOrPrimitive<UInt32> precision,
            StringOrPrimitive<UInt32> scale, BoolOrNone unicode, StringOrNone collation, string concurrencyMode)
        {
            ValidatePrereqCommand(prereq);

            _theDefault = theDefault;
            _maxLength = maxLength;
            _fixedLength = fixedLength;
            _precision = precision;
            _scale = scale;
            _unicode = unicode;
            _collation = collation;
            _concurrencyMode = concurrencyMode;

            AddPreReqCommand(prereq);
        }
        /// <summary>
        ///     Creates a new property in the passed in storage entity and optionally sets additional
        ///     facets on the property.
        ///     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 commited.
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="name">The name of the property</param>
        /// <param name="entityType">Must be a storage entity</param>
        /// <param name="type">The type to use for this property (cannot be empty)</param>
        /// <param name="nullable">Flag whether the property is nullable or not</param>
        /// <param name="theDefault">Optional: the default value for this property</param>
        /// <param name="maxLength">Optional facet</param>
        /// <param name="fixedLength">Optional facet</param>
        /// <param name="precision">Optional facet</param>
        /// <param name="scale">Optional facet</param>
        /// <param name="unicode">Optional facet</param>
        /// <param name="collation">Optional facet</param>
        /// <param name="concurrencyMode">Optional: the concurrency mode for this property</param>
        /// <returns>The new Property</returns>
        internal static Property CreateStorageProperty(
            CommandProcessorContext cpc, string name, StorageEntityType entityType,
            string type, bool?nullable, StringOrNone theDefault, StringOrPrimitive <UInt32> maxLength, BoolOrNone fixedLength,
            StringOrPrimitive <UInt32> precision,
            StringOrPrimitive <UInt32> scale, BoolOrNone unicode, StringOrNone collation, string concurrencyMode)
        {
            CommandValidation.ValidateStorageEntityType(entityType);

            var cpcd = new CreatePropertyCommand(name, entityType, type, nullable);
            var ssp  = new SetPropertyFacetsCommand(
                cpcd, theDefault, maxLength, fixedLength, precision, scale, unicode, collation, concurrencyMode);

            var cp = new CommandProcessor(cpc, cpcd, ssp);

            cp.Invoke();

            return(cpcd.CreatedProperty);
        }
示例#13
0
        /// <summary>
        ///     Sets facets on the property being created by the passed in command.
        /// </summary>
        /// <param name="prereq">Must be non-null command creating the storage property</param>
        /// <param name="theDefault">Optional facet</param>
        /// <param name="maxLength">Optional facet</param>
        /// <param name="fixedLength">Optional facet</param>
        /// <param name="precision">Optional facet</param>
        /// <param name="scale">Optional facet</param>
        /// <param name="unicode">Optional facet</param>
        /// <param name="collation">Optional facet</param>
        /// <param name="concurrencyMode">Optional facet</param>
        internal SetPropertyFacetsCommand(
            CreatePropertyCommand prereq, StringOrNone theDefault,
            StringOrPrimitive <UInt32> maxLength, BoolOrNone fixedLength, StringOrPrimitive <UInt32> precision,
            StringOrPrimitive <UInt32> scale, BoolOrNone unicode, StringOrNone collation, string concurrencyMode)
        {
            ValidatePrereqCommand(prereq);

            _theDefault      = theDefault;
            _maxLength       = maxLength;
            _fixedLength     = fixedLength;
            _precision       = precision;
            _scale           = scale;
            _unicode         = unicode;
            _collation       = collation;
            _concurrencyMode = concurrencyMode;

            AddPreReqCommand(prereq);
        }
        /// <summary>
        ///     Creates a new property in the passed in conceptual entity and optionally sets additional
        ///     facets on the property.
        ///     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 commited.
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="name">The name of the property</param>
        /// <param name="entityType">Must be a conceptual entity</param>
        /// <param name="type">The type to use for this property (cannot be empty)</param>
        /// <param name="nullable">Flag whether the property is nullable or not</param>
        /// <param name="theDefault">Optional: the default value for this property</param>
        /// <param name="concurrencyMode">Optional: the concurrency mode for this property</param>
        /// <param name="getterAccessModifier">Optional: Get access modifier.</param>
        /// <param name="setterAccessModifier">Optional: Set access modifier.</param>
        /// <returns>The new Property</returns>
        internal static Property CreateConceptualProperty(
            CommandProcessorContext cpc, string name, ConceptualEntityType entityType,
            string type, bool?nullable, StringOrNone theDefault, string concurrencyMode, string getterAccessModifier,
            string setterAccessModifier,
            StringOrPrimitive <UInt32> maxLength, bool?fixedLength, StringOrPrimitive <UInt32> precision, StringOrPrimitive <UInt32> scale,
            bool?unicode, StringOrNone collation, string storeGeneratedPattern, InsertPropertyPosition insertPosition)
        {
            CommandValidation.ValidateConceptualEntityType(entityType);

            var cpcd = new CreatePropertyCommand(name, entityType, type, nullable, insertPosition);
            var scp  = new SetConceptualPropertyFacetsCommand(
                cpcd, theDefault, concurrencyMode, getterAccessModifier, setterAccessModifier,
                maxLength, DefaultableValueBoolOrNone.GetFromNullableBool(fixedLength), precision, scale,
                DefaultableValueBoolOrNone.GetFromNullableBool(unicode), collation);
            var scpac = new SetConceptualPropertyAnnotationsCommand(cpcd, storeGeneratedPattern);

            var cp = new CommandProcessor(cpc, cpcd, scp, scpac);

            cp.Invoke();

            return(cpcd.CreatedProperty);
        }
        /// <summary>
        ///     Creates a new property in the passed in conceptual entity and optionally sets additional
        ///     facets on the property.
        ///     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 commited.
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="name">The name of the property</param>
        /// <param name="entityType">Must be a conceptual entity</param>
        /// <param name="type">The type to use for this property (cannot be empty)</param>
        /// <param name="nullable">Flag whether the property is nullable or not</param>
        /// <param name="theDefault">Optional: the default value for this property</param>
        /// <param name="concurrencyMode">Optional: the concurrency mode for this property</param>
        /// <param name="getterAccessModifier">Optional: Get access modifier.</param>
        /// <param name="setterAccessModifier">Optional: Set access modifier.</param>
        /// <returns>The new Property</returns>
        internal static Property CreateConceptualProperty(
            CommandProcessorContext cpc, string name, ConceptualEntityType entityType,
            string type, bool? nullable, StringOrNone theDefault, string concurrencyMode, string getterAccessModifier,
            string setterAccessModifier,
            StringOrPrimitive<UInt32> maxLength, bool? fixedLength, StringOrPrimitive<UInt32> precision, StringOrPrimitive<UInt32> scale,
            bool? unicode, StringOrNone collation, string storeGeneratedPattern, InsertPropertyPosition insertPosition)
        {
            CommandValidation.ValidateConceptualEntityType(entityType);

            var cpcd = new CreatePropertyCommand(name, entityType, type, nullable, insertPosition);
            var scp = new SetConceptualPropertyFacetsCommand(
                cpcd, theDefault, concurrencyMode, getterAccessModifier, setterAccessModifier,
                maxLength, DefaultableValueBoolOrNone.GetFromNullableBool(fixedLength), precision, scale,
                DefaultableValueBoolOrNone.GetFromNullableBool(unicode), collation);
            var scpac = new SetConceptualPropertyAnnotationsCommand(cpcd, storeGeneratedPattern);

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

            return cpcd.CreatedProperty;
        }
        /// <summary>
        ///     Creates a new property in the passed in storage entity and optionally sets additional
        ///     facets on the property.
        ///     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 commited.
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="name">The name of the property</param>
        /// <param name="entityType">Must be a storage entity</param>
        /// <param name="type">The type to use for this property (cannot be empty)</param>
        /// <param name="nullable">Flag whether the property is nullable or not</param>
        /// <param name="theDefault">Optional: the default value for this property</param>
        /// <param name="maxLength">Optional facet</param>
        /// <param name="fixedLength">Optional facet</param>
        /// <param name="precision">Optional facet</param>
        /// <param name="scale">Optional facet</param>
        /// <param name="unicode">Optional facet</param>
        /// <param name="collation">Optional facet</param>
        /// <param name="concurrencyMode">Optional: the concurrency mode for this property</param>
        /// <returns>The new Property</returns>
        internal static Property CreateStorageProperty(
            CommandProcessorContext cpc, string name, StorageEntityType entityType,
            string type, bool? nullable, StringOrNone theDefault, StringOrPrimitive<UInt32> maxLength, BoolOrNone fixedLength,
            StringOrPrimitive<UInt32> precision,
            StringOrPrimitive<UInt32> scale, BoolOrNone unicode, StringOrNone collation, string concurrencyMode)
        {
            CommandValidation.ValidateStorageEntityType(entityType);

            var cpcd = new CreatePropertyCommand(name, entityType, type, nullable);
            var ssp = new SetPropertyFacetsCommand(
                cpcd, theDefault, maxLength, fixedLength, precision, scale, unicode, collation, concurrencyMode);

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

            return cpcd.CreatedProperty;
        }
        /// <summary>
        ///     This helper function is an easy way to get a new entity type, entity set and key property in the
        ///     new entity type created in the conceptual or storage model.
        ///     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 commited.
        /// </summary>
        /// <param name="cpc"></param>
        /// <param name="name">The name of the new entity</param>
        /// <param name="setName">The name of the new set</param>
        /// <param name="createKeyProperty">A flag whether to create a new key property or not (sending false creates no new property)</param>
        /// <param name="propertyName">The name of the new property</param>
        /// <param name="propertyType">The type of the new property</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>
        /// <param name="isDefaultName">Flag whether the name is the default for new entity types/sets</param>
        /// <returns>The new EntityType</returns>
        internal static EntityType CreateEntityTypeAndEntitySetAndProperty(
            CommandProcessorContext cpc,
            string name, string setName, bool createKeyProperty, string propertyName,
            string propertyType, string propertyStoreGeneratedPattern, ModelSpace modelSpace, bool uniquifyNames, bool isDefaultName = false)
        {
            var cp = new CommandProcessor(cpc);

            var cet = new CreateEntityTypeCommand(name, modelSpace, uniquifyNames);
            cet.CreateWithDefaultName = isDefaultName;
            cp.EnqueueCommand(cet);

            var ces = new CreateEntitySetCommand(setName, cet, modelSpace, uniquifyNames);
            cp.EnqueueCommand(ces);

            if (createKeyProperty)
            {
                var cpcd = new CreatePropertyCommand(propertyName, cet, propertyType, false);
                cpcd.IsIdProperty = true;
                cp.EnqueueCommand(cpcd);

                var skpc = new SetKeyPropertyCommand(cpcd, true);
                cp.EnqueueCommand(skpc);

                var ssgpc = new SetStoreGeneratedPatternCommand(cpcd, propertyStoreGeneratedPattern);
                cp.EnqueueCommand(ssgpc);
            }

            cp.Invoke();

            return cet.EntityType;
        }
        /// <summary>
        ///     Creates a property in the passed in entity of the default Type (non-nullable String).
        ///     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 commited.
        /// </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 Property</returns>
        internal static Property CreateDefaultProperty(CommandProcessorContext cpc, string name, EntityType entityType)
        {
            var cpcd = new CreatePropertyCommand(
                name, entityType, ModelConstants.DefaultPropertyType, ModelConstants.DefaultPropertyNullability);
            cpcd._createWithDefaultName = true;

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

            return cpcd.CreatedProperty;
        }
示例#19
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;
            }
        }