Exemplo n.º 1
0
        private void HandlePropertyElement(XmlReader reader)
        {
            StructuredProperty structuredProperty = new StructuredProperty(this);

            structuredProperty.Parse(reader);
            this.AddMember((SchemaElement)structuredProperty);
        }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="reader"> </param>
        private void HandlePropertyElement(XmlReader reader)
        {
            var property = new StructuredProperty(this);

            property.Parse(reader);

            AddMember(property);
        }
Exemplo n.º 3
0
 internal bool ResolveNames(SchemaEntityType entityType)
 {
     if (string.IsNullOrEmpty(this.Name))
     {
         return(true);
     }
     this._property = entityType.FindProperty(this.Name);
     return(this._property != null);
 }
Exemplo n.º 4
0
        /// <summary>
        ///     Since this method can be used in different context, this method does not add any errors
        ///     Please make sure that the caller of this methods handles the error case and add errors
        ///     appropriately
        /// </summary>
        internal bool ResolveNames(SchemaEntityType entityType)
        {
            if (string.IsNullOrEmpty(Name))
            {
                // Don't flag this error. This must already must have flaged as error, while handling name attribute
                return(true);
            }

            // Make sure there is a property by this name
            _property = entityType.FindProperty(Name);

            return(_property != null);
        }
        /// <summary>
        ///     Since this method can be used in different context, this method does not add any errors
        ///     Please make sure that the caller of this methods handles the error case and add errors
        ///     appropriately
        /// </summary>
        /// <param name="entityType"> </param>
        /// <returns> </returns>
        internal bool ResolveNames(SchemaEntityType entityType)
        {
            if (string.IsNullOrEmpty(Name))
            {
                // Don't flag this error. This must already must have flaged as error, while handling name attribute
                return true;
            }

            // Make sure there is a property by this name
            _property = entityType.FindProperty(Name);

            return (_property != null);
        }
Exemplo n.º 6
0
        public StructuredProperty FindProperty(string name)
        {
            StructuredProperty structuredProperty = this.Properties.LookUpEquivalentKey(name);

            if (structuredProperty != null)
            {
                return(structuredProperty);
            }
            if (this.IsTypeHierarchyRoot)
            {
                return((StructuredProperty)null);
            }
            return(this.BaseType.FindProperty(name));
        }
Exemplo n.º 7
0
        internal override void Validate()
        {
            Dictionary <string, PropertyRefElement> dictionary = new Dictionary <string, PropertyRefElement>((IEqualityComparer <string>)StringComparer.Ordinal);

            foreach (PropertyRefElement keyProperty in this._keyProperties)
            {
                StructuredProperty property = keyProperty.Property;
                if (dictionary.ContainsKey(property.Name))
                {
                    this.AddError(ErrorCode.DuplicatePropertySpecifiedInEntityKey, EdmSchemaErrorSeverity.Error, (object)Strings.DuplicatePropertyNameSpecifiedInEntityKey((object)this.ParentElement.FQName, (object)property.Name));
                }
                else
                {
                    dictionary.Add(property.Name, keyProperty);
                    if (property.Nullable)
                    {
                        this.AddError(ErrorCode.InvalidKey, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidKeyNullablePart((object)property.Name, (object)this.ParentElement.Name));
                    }
                    if (!(property.Type is ScalarType) && !(property.Type is SchemaEnumType) || property.CollectionKind != CollectionKind.None)
                    {
                        this.AddError(ErrorCode.EntityKeyMustBeScalar, EdmSchemaErrorSeverity.Error, (object)Strings.EntityKeyMustBeScalar((object)property.Name, (object)this.ParentElement.Name));
                    }
                    else if (!(property.Type is SchemaEnumType))
                    {
                        PrimitiveType edmType = (PrimitiveType)property.TypeUsage.EdmType;
                        if (this.Schema.DataModel == SchemaDataModelOption.EntityDataModel)
                        {
                            if (edmType.PrimitiveTypeKind == PrimitiveTypeKind.Binary && this.Schema.SchemaVersion < 2.0 || Helper.IsSpatialType(edmType))
                            {
                                this.AddError(ErrorCode.EntityKeyTypeCurrentlyNotSupported, EdmSchemaErrorSeverity.Error, (object)Strings.EntityKeyTypeCurrentlyNotSupported((object)property.Name, (object)this.ParentElement.FQName, (object)edmType.PrimitiveTypeKind));
                            }
                        }
                        else if (edmType.PrimitiveTypeKind == PrimitiveTypeKind.Binary && this.Schema.SchemaVersion < 2.0 || Helper.IsSpatialType(edmType))
                        {
                            this.AddError(ErrorCode.EntityKeyTypeCurrentlyNotSupported, EdmSchemaErrorSeverity.Error, (object)Strings.EntityKeyTypeCurrentlyNotSupportedInSSDL((object)property.Name, (object)this.ParentElement.FQName, (object)property.TypeUsage.EdmType.Name, (object)property.TypeUsage.EdmType.BaseType.FullName, (object)edmType.PrimitiveTypeKind));
                        }
                    }
                }
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="reader"> </param>
        private void HandlePropertyElement(XmlReader reader)
        {
            var property = new StructuredProperty(this);

            property.Parse(reader);

            AddMember(property);
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Converts a property from SOM to metadata
        /// </summary>
        /// <param name="somProperty"> The SOM element to process </param>
        /// <param name="providerManifest"> The provider manifest to be used for conversion </param>
        /// <param name="convertedItemCache"> The item collection for currently existing metadata objects </param>
        /// <param name="newGlobalItems"> The new GlobalItem objects that are created as a result of this conversion </param>
        /// <returns> The property object resulting from the convert </returns>
        private static EdmProperty ConvertToProperty(
            StructuredProperty somProperty,
            DbProviderManifest providerManifest,
            ConversionCache convertedItemCache,
            Dictionary<SchemaElement, GlobalItem> newGlobalItems)
        {
            EdmProperty property;

            // Get the appropriate type object for this type, for primitive and enum types, get the facet values for the type
            // property as a type usage object as well                  
            TypeUsage typeUsage = null;

            var scalarType = somProperty.Type as ScalarType;

            if (scalarType != null
                && somProperty.Schema.DataModel != SchemaDataModelOption.EntityDataModel)
            {
                // parsing ssdl
                typeUsage = somProperty.TypeUsage;
                UpdateSentinelValuesInFacets(ref typeUsage);
            }
            else
            {
                EdmType propertyType;

                if (scalarType != null)
                {
                    Debug.Assert(somProperty.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType);
                    // try to get the instance of the primitive type from the item collection so that it back pointer is set.
                    propertyType = convertedItemCache.ItemCollection.GetItem<PrimitiveType>(somProperty.TypeUsage.EdmType.FullName);
                }
                else
                {
                    propertyType = (EdmType)LoadSchemaElement(somProperty.Type, providerManifest, convertedItemCache, newGlobalItems);
                }

                if (somProperty.CollectionKind
                    != CollectionKind.None)
                {
                    typeUsage = TypeUsage.Create(new CollectionType(propertyType));
                }
                else
                {
                    var enumType = scalarType == null ? somProperty.Type as SchemaEnumType : null;
                    typeUsage = TypeUsage.Create(propertyType);
                    if (enumType != null)
                    {
                        somProperty.EnsureEnumTypeFacets(convertedItemCache, newGlobalItems);
                    }

                    if (somProperty.TypeUsage != null)
                    {
                        ApplyTypePropertyFacets(somProperty.TypeUsage, ref typeUsage);
                    }
                }
            }

            PopulateGeneralFacets(somProperty, ref typeUsage);
            property = new EdmProperty(somProperty.Name, typeUsage);

            // Extract the optional Documentation
            if (somProperty.Documentation != null)
            {
                property.Documentation = ConvertToDocumentation(somProperty.Documentation);
            }
            AddOtherContent(somProperty, property);

            return property;
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Populate the facets on the TypeUsage object for a property
        /// </summary>
        /// <param name="somProperty"> The property containing the information </param>
        /// <param name="propertyTypeUsage"> The type usage object where to populate facet </param>
        private static void PopulateGeneralFacets(
            StructuredProperty somProperty,
            ref TypeUsage propertyTypeUsage)
        {
            var madeChanges = false;
            var facets = propertyTypeUsage.Facets.ToDictionary(f => f.Name);
            if (!somProperty.Nullable)
            {
                facets[DbProviderManifest.NullableFacetName] = Facet.Create(MetadataItem.NullableFacetDescription, false);
                madeChanges = true;
            }

            if (somProperty.Default != null)
            {
                facets[DbProviderManifest.DefaultValueFacetName] = Facet.Create(
                    MetadataItem.DefaultValueFacetDescription, somProperty.DefaultAsObject);
                madeChanges = true;
            }

            //This is not really a general facet
            //If we are dealing with a 1.1 Schema, Add a facet for CollectionKind
            if (somProperty.Schema.SchemaVersion
                == XmlConstants.EdmVersionForV1_1)
            {
                var newFacet = Facet.Create(MetadataItem.CollectionKindFacetDescription, somProperty.CollectionKind);
                facets.Add(newFacet.Name, newFacet);
                madeChanges = true;
            }

            if (madeChanges)
            {
                propertyTypeUsage = TypeUsage.Create(propertyTypeUsage.EdmType, facets.Values);
            }
        }