Esempio n. 1
0
        internal override void Validate()
        {
            base.Validate();

            ValidationHelper.ValidateTypeDeclaration(this, _type, _typeSubElement);

            if (Schema.DataModel != SchemaDataModelOption.EntityDataModel)
            {
                Debug.Assert(Schema.DataModel == SchemaDataModelOption.ProviderDataModel ||
                             Schema.DataModel == SchemaDataModelOption.ProviderManifestModel, "Unexpected data model");

                bool collectionAllowed = this.ParentElement.IsAggregate;

                // Only scalar parameters are allowed for functions in s-space.
                Debug.Assert(_typeSubElement == null, "Unexpected type subelement inside <Parameter> element.");
                if (_type != null && (_type is ScalarType == false || (!collectionAllowed && _collectionKind != CollectionKind.None)))
                {
                    string typeName = "";
                    if (_type != null)
                    {
                        typeName = Function.GetTypeNameForErrorMessage(_type, _collectionKind, _isRefType);
                    }
                    else if (_typeSubElement != null)
                    {
                        typeName = _typeSubElement.FQName;
                    }
                    if (Schema.DataModel == SchemaDataModelOption.ProviderManifestModel)
                    {
                        AddError(ErrorCode.FunctionWithNonEdmTypeNotSupported,
                                 EdmSchemaErrorSeverity.Error,
                                 this,
                                 System.Data.Entity.Strings.FunctionWithNonEdmPrimitiveTypeNotSupported(typeName, this.ParentElement.FQName));
                    }
                    else
                    {
                        AddError(ErrorCode.FunctionWithNonPrimitiveTypeNotSupported,
                                 EdmSchemaErrorSeverity.Error,
                                 this,
                                 System.Data.Entity.Strings.FunctionWithNonPrimitiveTypeNotSupported(typeName, this.ParentElement.FQName));
                    }
                    return;
                }
            }

            ValidationHelper.ValidateFacets(this, _type, _typeUsageBuilder);

            if (_isRefType)
            {
                ValidationHelper.ValidateRefType(this, _type);
            }


            if (_typeSubElement != null)
            {
                _typeSubElement.Validate();
            }
        }
Esempio n. 2
0
        internal override void Validate()
        {
            base.Validate();

            ValidationHelper.ValidateTypeDeclaration(this, _type, _typeSubElement);
            ValidationHelper.ValidateFacets(this, _type, _typeUsageBuilder);
            if (_isRefType)
            {
                ValidationHelper.ValidateRefType(this, _type);
            }

            if (Schema.DataModel != SchemaDataModelOption.EntityDataModel)
            {
                Debug.Assert(Schema.DataModel == SchemaDataModelOption.ProviderDataModel ||
                             Schema.DataModel == SchemaDataModelOption.ProviderManifestModel, "Unexpected data model");

                if (Schema.DataModel == SchemaDataModelOption.ProviderManifestModel)
                {
                    // Only scalar return type is allowed for functions in provider manifest.
                    if (_type != null && (_type is ScalarType == false || _collectionKind != CollectionKind.None) ||
                        _typeSubElement != null && _typeSubElement.Type is ScalarType == false)
                    {
                        string typeName = "";
                        if (_type != null)
                        {
                            typeName = Function.GetTypeNameForErrorMessage(_type, _collectionKind, _isRefType);
                        }
                        else if (_typeSubElement != null)
                        {
                            typeName = _typeSubElement.FQName;
                        }
                        AddError(ErrorCode.FunctionWithNonEdmTypeNotSupported,
                                 EdmSchemaErrorSeverity.Error,
                                 this,
                                 System.Data.Entity.Strings.FunctionWithNonEdmPrimitiveTypeNotSupported(typeName, this.ParentElement.FQName));
                    }
                }
                else // SchemaDataModelOption.ProviderDataModel
                {
                    Debug.Assert(Schema.DataModel == SchemaDataModelOption.ProviderDataModel, "Unexpected data model");

                    // In SSDL, function may only return a primitive type or a collection of rows.
                    if (_type != null)
                    {
                        // It is not possible to define a collection of rows via a type attribute, hence any collection is not allowed.
                        if (_type is ScalarType == false || _collectionKind != CollectionKind.None)
                        {
                            AddError(ErrorCode.FunctionWithNonPrimitiveTypeNotSupported,
                                     EdmSchemaErrorSeverity.Error,
                                     this,
                                     System.Data.Entity.Strings.FunctionWithNonPrimitiveTypeNotSupported(_isRefType ? _unresolvedType : _type.FQName, this.ParentElement.FQName));
                        }
                    }
                    else if (_typeSubElement != null)
                    {
                        if (_typeSubElement.Type is ScalarType == false)
                        {
                            if (Schema.SchemaVersion < XmlConstants.StoreVersionForV3)
                            {
                                // Before V3 provider model functions only supported scalar return types.
                                AddError(ErrorCode.FunctionWithNonPrimitiveTypeNotSupported,
                                         EdmSchemaErrorSeverity.Error,
                                         this,
                                         System.Data.Entity.Strings.FunctionWithNonPrimitiveTypeNotSupported(_typeSubElement.FQName, this.ParentElement.FQName));
                            }
                            else
                            {
                                // Starting from V3, TVFs must return collection of rows and row props can be only primitive types.
                                // The "collection of rows" is the only option in SSDL function ReturnType subelement thus it's enforced on the XSD level,
                                // so we can assume it here. The only thing we need to check is the type of the row properties.
                                var collection = _typeSubElement as CollectionTypeElement;
                                Debug.Assert(collection != null, "Can't find <CollectionType> inside TVF <ReturnType> element");
                                if (collection != null)
                                {
                                    var row = collection.SubElement as RowTypeElement;
                                    Debug.Assert(row != null, "Can't find <RowType> inside TVF <ReturnType><CollectionType> element");
                                    if (row != null)
                                    {
                                        if (row.Properties.Any(p => !p.ValidateIsScalar()))
                                        {
                                            AddError(ErrorCode.TVFReturnTypeRowHasNonScalarProperty,
                                                     EdmSchemaErrorSeverity.Error,
                                                     this,
                                                     System.Data.Entity.Strings.TVFReturnTypeRowHasNonScalarProperty);
                                        }
                                    }
                                }
                            }
                        }
                        // else type is ScalarType which is supported in all version
                    }
                }
            }

            if (_typeSubElement != null)
            {
                _typeSubElement.Validate();
            }
        }