/// <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);
        }
Exemple #2
0
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // get unique name for the property
            var propertyName = ModelHelper.GetUniqueName(typeof(ConceptualProperty), _parentComplexType, _clipboardProperty.PropertyName);

            if (!_clipboardProperty.IsComplexProperty)
            {
                // scalar property case
                var cmd = new CreateComplexTypePropertyCommand(
                    propertyName, _parentComplexType, _clipboardProperty.PropertyType, _clipboardProperty.IsNullable);
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
                _createdProperty = cmd.Property;
            }
            else
            {
                // complex property case
                // first try to find ComplexType by it's name
                var complexTypeNormalizedName = EFNormalizableItemDefaults.DefaultNameNormalizerForEDM(
                    _parentComplexType, _clipboardProperty.PropertyType);
                var         items       = _parentComplexType.Artifact.ArtifactSet.GetSymbolList(complexTypeNormalizedName.Symbol);
                ComplexType complexType = null;
                foreach (var efElement in items)
                {
                    // the GetSymbolList() method might return more than one element so choose the first ComplexType
                    complexType = efElement as ComplexType;
                    if (complexType != null)
                    {
                        break;
                    }
                }
                if (complexType != null)
                {
                    // if the ComplexType is found, simply use the create command
                    var cmd = new CreateComplexTypePropertyCommand(propertyName, _parentComplexType, complexType, false);
                    CommandProcessor.InvokeSingleCommand(cpc, cmd);
                    _createdProperty = cmd.Property;
                }
                else
                {
                    // in this case we're going to create ComplexProperty with unresolved type
                    var complexProperty = new ComplexConceptualProperty(_parentComplexType, null);
                    complexProperty.ComplexType.SetXAttributeValue(_clipboardProperty.PropertyType);
                    // set the name and add to the parent entity
                    complexProperty.LocalName.Value = propertyName;
                    _parentComplexType.AddProperty(complexProperty);

                    // set other attributes of the property
                    complexProperty.Nullable.Value = BoolOrNone.FalseValue;

                    XmlModelHelper.NormalizeAndResolve(complexProperty);
                    Debug.Assert(
                        complexProperty.ComplexType.Status != BindingStatus.Known,
                        "Why didn't we find the ComplexType in the ArtifactSet previously?");
                    _createdProperty = complexProperty;
                }
            }

            // safety check
            Debug.Assert(_createdProperty != null, "We didn't get good Property out of the command");
            if (_createdProperty != null)
            {
                // set Property attributes
                var cmd2 = new SetConceptualPropertyFacetsCommand(
                    _createdProperty, _clipboardProperty.Default,
                    _clipboardProperty.ConcurrencyMode, _clipboardProperty.GetterAccessModifier, _clipboardProperty.SetterAccessModifier,
                    _clipboardProperty.MaxLength,
                    DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.FixedLength), _clipboardProperty.Precision,
                    _clipboardProperty.Scale,
                    DefaultableValueBoolOrNone.GetFromNullableBool(_clipboardProperty.Unicode), _clipboardProperty.Collation);
                CommandProcessor.InvokeSingleCommand(cpc, cmd2);
            }
        }
Exemple #3
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;
            }
        }
        private static string GetColumnNullableFacetText(DefaultableValueBoolOrNone nullableDefaultableValue)
        {
            var primitiveValue = nullableDefaultableValue.Value.PrimitiveValue;
            if (null != nullableDefaultableValue.Value.StringValue)
            {
                // isNullable is set to 'None' - so use default
                StringOrPrimitive<bool> defaultValue = nullableDefaultableValue.DefaultValue;
                if (null == defaultValue.StringValue)
                {
                    primitiveValue = defaultValue.PrimitiveValue;
                }
                else
                {
                    // even default is set to 'None'
                    return null;
                }
            }

            if (primitiveValue)
            {
                return Condition.IsNullConstant;
            }
            else
            {
                return Condition.IsNotNullConstant;
            }
        }