/// <summary>
 ///     Create a Conceptual property at a specified position.
 /// </summary>
 /// <param name="parent">Property's Parent. The value is either ConceptualEntityTYpe or a ComplexType.</param>
 /// <param name="element">Property's XElement</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>
 public ConceptualProperty(EFElement parent, XElement element, InsertPropertyPosition insertPosition)
     : base(parent, element, insertPosition)
 {
     Debug.Assert(
         parent is ConceptualEntityType || parent is ComplexType,
         "Parent of ConceptualProperty should be either ConceptualEntityType or ComplexType");
 }
 /// <summary>
 ///     Allow the construction of a complex property at a specified position.
 /// </summary>
 /// <param name="parent">Property's Parent</param>
 /// <param name="element">Property's XElement</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 ComplexConceptualProperty(EFElement parent, XElement element, InsertPropertyPosition insertPosition)
     : base(parent, element, insertPosition)
 {
     Debug.Assert(
         parent is ConceptualEntityType || parent is ComplexType || parent == null,
         "Parent of ConceptualProperty should be either ConceptualEntityType or ComplexType (or null for testing)");
 }
 /// <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;
 }
Esempio n. 4
0
 /// <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;
 }
        /// <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 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 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;
        }
Esempio n. 8
0
        /// <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;
        }
Esempio n. 9
0
        /// <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>
        ///     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>
        ///     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>
 ///     Create a Navigation property at a specified position.
 /// </summary>
 /// <param name="parent">Property's Parent. The value is either ConceptualEntityTYpe or a ComplexType.</param>
 /// <param name="element">Property's XElement</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 NavigationProperty(EntityType parent, XElement element, InsertPropertyPosition insertPostion)
     : base(parent, element, insertPostion)
 {
     // Nothing
 }
        private static Property CreateConceptualProperty(ConceptualEntityType parentEntity, string name, string type, InsertPropertyPosition insertPosition)
        {
            var property = new ConceptualProperty(parentEntity, null, insertPosition);

            property.LocalName.Value = name;
            property.ChangePropertyType(type);
            return(property);
        }
        private static Property CreateProperty(
            EntityType parentEntity, string name, string type, BoolOrNone isNullable, InsertPropertyPosition insertPosition)
        {
            var conceptualEntity = parentEntity as ConceptualEntityType;

            Debug.Assert(conceptualEntity != null || parentEntity is StorageEntityType, "unexpected entity type");
            var property = conceptualEntity != null
                               ? CreateConceptualProperty(conceptualEntity, name, type, insertPosition)
                               : CreateStorageProperty((StorageEntityType)parentEntity, name, type);

            if (isNullable != null)
            {
                property.Nullable.Value = isNullable;
            }

            return(property);
        }
        /// <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;
        }
 private static Property CreateConceptualProperty(ConceptualEntityType parentEntity, string name, string type, InsertPropertyPosition insertPosition)
 {
     var property = new ConceptualProperty(parentEntity, null, insertPosition);
     property.LocalName.Value = name;
     property.ChangePropertyType(type);
     return 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;
 }
Esempio n. 18
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);
        }
        private static Property CreateProperty(
            EntityType parentEntity, string name, string type, BoolOrNone isNullable, InsertPropertyPosition insertPosition)
        {
            var conceptualEntity = parentEntity as ConceptualEntityType;
            Debug.Assert(conceptualEntity != null || parentEntity is StorageEntityType, "unexpected entity type");
            var property = conceptualEntity != null
                               ? CreateConceptualProperty(conceptualEntity, name, type, insertPosition)
                               : CreateStorageProperty((StorageEntityType)parentEntity, name, type);

            if (isNullable != null)
            {
                property.Nullable.Value = isNullable;
            }

            return property;
        }