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) { var typeName = ""; if (_type != null) { typeName = Function.GetTypeNameForErrorMessage(_type, _collectionKind, _isRefType); } else if (_typeSubElement != null) { typeName = _typeSubElement.FQName; } AddError( ErrorCode.FunctionWithNonEdmTypeNotSupported, EdmSchemaErrorSeverity.Error, this, Strings.FunctionWithNonEdmPrimitiveTypeNotSupported(typeName, 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, Strings.FunctionWithNonPrimitiveTypeNotSupported( _isRefType ? _unresolvedType : _type.FQName, 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, Strings.FunctionWithNonPrimitiveTypeNotSupported(_typeSubElement.FQName, 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, Strings.TVFReturnTypeRowHasNonScalarProperty); } } } } } // else type is ScalarType which is supported in all version } } } if (_typeSubElement != null) { _typeSubElement.Validate(); } }