Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        private void HandlePropertyElement(XmlReader reader)
        {
            StructuredProperty property = new StructuredProperty(this);

            property.Parse(reader);

            AddMember(property);
        }
Exemplo n.º 2
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>
        /// <param name="entityType"></param>
        /// <returns></returns>
        internal bool ResolveNames(SchemaEntityType entityType)
        {
            if (string.IsNullOrEmpty(this.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(this.Name);

            return (_property != null);
        }
Exemplo n.º 3
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>
        /// <param name="entityType"></param>
        /// <returns></returns>
        internal bool ResolveNames(SchemaEntityType entityType)
        {
            if (string.IsNullOrEmpty(this.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(this.Name);

            return(_property != null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Find a property by name in the type hierarchy
        /// </summary>
        /// <param name="name">simple property name</param>
        /// <returns>the StructuredProperty object if name exists, null otherwise</returns>
        public StructuredProperty FindProperty(string name)
        {
            StructuredProperty property = Properties.LookUpEquivalentKey(name);

            if (property != null)
            {
                return(property);
            }

            if (IsTypeHierarchyRoot)
            {
                return(null);
            }

            return(BaseType.FindProperty(name));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        private void HandlePropertyElement(XmlReader reader)
        {
            StructuredProperty property = new StructuredProperty(this);

            property.Parse(reader);

            AddMember(property);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Validate all the key properties
        /// </summary>
        internal override void Validate()
        {
            Debug.Assert(_keyProperties != null, "xsd should have verified that there should be atleast one property ref element");
            Dictionary <string, PropertyRefElement> propertyLookUp = new Dictionary <string, PropertyRefElement>(StringComparer.Ordinal);

            foreach (PropertyRefElement keyProperty in _keyProperties)
            {
                StructuredProperty property = keyProperty.Property;
                Debug.Assert(property != null, "This should never be null, since if we were not able to resolve, we should have never reached to this point");

                if (propertyLookUp.ContainsKey(property.Name))
                {
                    AddError(ErrorCode.DuplicatePropertySpecifiedInEntityKey, EdmSchemaErrorSeverity.Error,
                             System.Data.Entity.Strings.DuplicatePropertyNameSpecifiedInEntityKey(this.ParentElement.FQName, property.Name));
                    continue;
                }

                propertyLookUp.Add(property.Name, keyProperty);

                if (property.Nullable)
                {
                    AddError(ErrorCode.InvalidKey, EdmSchemaErrorSeverity.Error,
                             System.Data.Entity.Strings.InvalidKeyNullablePart(property.Name, this.ParentElement.Name));
                }

                // currently we only support key properties of scalar type
                if (!(property.Type is ScalarType || property.Type is SchemaEnumType) || (property.CollectionKind != CollectionKind.None))
                {
                    AddError(ErrorCode.EntityKeyMustBeScalar,
                             EdmSchemaErrorSeverity.Error,
                             System.Data.Entity.Strings.EntityKeyMustBeScalar(property.Name, this.ParentElement.Name));
                    continue;
                }

                // Enum properties are never backed by binary or spatial type so we can skip the checks here
                if (!(property.Type is SchemaEnumType))
                {
                    Debug.Assert(property.TypeUsage != null, "For scalar type, typeusage must be initialized");

                    PrimitiveType primitivePropertyType = (PrimitiveType)property.TypeUsage.EdmType;
                    if (Schema.DataModel == SchemaDataModelOption.EntityDataModel)
                    {
                        // Binary keys are only supported for V2.0 CSDL, Spatial keys are not supported.
                        if ((primitivePropertyType.PrimitiveTypeKind == PrimitiveTypeKind.Binary && Schema.SchemaVersion < XmlConstants.EdmVersionForV2) ||
                            Helper.IsSpatialType(primitivePropertyType))
                        {
                            AddError(ErrorCode.EntityKeyTypeCurrentlyNotSupported,
                                     EdmSchemaErrorSeverity.Error,
                                     Strings.EntityKeyTypeCurrentlyNotSupported(property.Name, this.ParentElement.FQName, primitivePropertyType.PrimitiveTypeKind));
                        }
                    }
                    else
                    {
                        Debug.Assert(SchemaDataModelOption.ProviderDataModel == Schema.DataModel, "Invalid DataModel encountered");

                        // Binary keys are only supported for V2.0 SSDL, Spatial keys are not supported.
                        if ((primitivePropertyType.PrimitiveTypeKind == PrimitiveTypeKind.Binary && Schema.SchemaVersion < XmlConstants.StoreVersionForV2) ||
                            Helper.IsSpatialType(primitivePropertyType))
                        {
                            AddError(ErrorCode.EntityKeyTypeCurrentlyNotSupported,
                                     EdmSchemaErrorSeverity.Error,
                                     Strings.EntityKeyTypeCurrentlyNotSupportedInSSDL(property.Name, this.ParentElement.FQName,
                                                                                      property.TypeUsage.EdmType.Name, property.TypeUsage.EdmType.BaseType.FullName, primitivePropertyType.PrimitiveTypeKind));
                        }
                    }
                }
            }
        }