internal static void ValidateFacets( SchemaElement element, SchemaType type, TypeUsageBuilder typeUsageBuilder) { if (type != null) { SchemaEnumType schemaEnumType = type as SchemaEnumType; if (schemaEnumType != null) { typeUsageBuilder.ValidateEnumFacets(schemaEnumType); } else { if (type is ScalarType || !typeUsageBuilder.HasUserDefinedFacets) { return; } element.AddError(ErrorCode.FacetOnNonScalarType, EdmSchemaErrorSeverity.Error, (object)Strings.FacetsOnNonScalarType((object)type.FQName)); } } else { if (!typeUsageBuilder.HasUserDefinedFacets) { return; } element.AddError(ErrorCode.IncorrectlyPlacedFacet, EdmSchemaErrorSeverity.Error, (object)Strings.FacetDeclarationRequiresTypeAttribute); } }
// <summary> // Validates whether facets are declared correctly. // </summary> // <param name="element"> Schema element being validated. Must not be null. </param> // <param name="type"> Resolved type (from declaration on the element). Possibly null. </param> // <param name="typeUsageBuilder"> TypeUsageBuilder for the current element. Must not be null. </param> internal static void ValidateFacets(SchemaElement element, SchemaType type, TypeUsageBuilder typeUsageBuilder) { DebugCheck.NotNull(element); DebugCheck.NotNull(typeUsageBuilder); if (type != null) { var schemaEnumType = type as SchemaEnumType; if (schemaEnumType != null) { typeUsageBuilder.ValidateEnumFacets(schemaEnumType); } else if (!(type is ScalarType) && typeUsageBuilder.HasUserDefinedFacets) { Debug.Assert(!(type is SchemaEnumType), "Note that enums should have already been handled."); // Non-scalar type should not have Facets. element.AddError( ErrorCode.FacetOnNonScalarType, EdmSchemaErrorSeverity.Error, Strings.FacetsOnNonScalarType(type.FQName)); } } else { if (typeUsageBuilder.HasUserDefinedFacets) { // Type attribute not specified but facets exist. element.AddError( ErrorCode.IncorrectlyPlacedFacet, EdmSchemaErrorSeverity.Error, Strings.FacetDeclarationRequiresTypeAttribute); } } }
internal static void ValidateTypeDeclaration( SchemaElement element, SchemaType type, SchemaElement typeSubElement) { if (type == null && typeSubElement == null) { element.AddError(ErrorCode.TypeNotDeclared, EdmSchemaErrorSeverity.Error, (object)Strings.TypeMustBeDeclared); } if (type == null || typeSubElement == null) { return; } element.AddError(ErrorCode.TypeDeclaredAsAttributeAndElement, EdmSchemaErrorSeverity.Error, (object)Strings.TypeDeclaredAsAttributeAndElement); }
private void ValidateFunctionImportReturnType( SchemaElement owner, SchemaType returnType, EntityContainerEntitySet entitySet, bool entitySetPathDefined) { SchemaEntityType schemaEntityType = returnType as SchemaEntityType; if (entitySet != null && entitySetPathDefined) { owner.AddError(ErrorCode.FunctionImportEntitySetAndEntitySetPathDeclared, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportEntitySetAndEntitySetPathDeclared((object)this.FQName)); } if (schemaEntityType != null) { if (entitySet == null) { owner.AddError(ErrorCode.FunctionImportReturnsEntitiesButDoesNotSpecifyEntitySet, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportReturnEntitiesButDoesNotSpecifyEntitySet((object)this.FQName)); } else { if (entitySet.EntityType == null || schemaEntityType.IsOfType((StructuredType)entitySet.EntityType)) { return; } owner.AddError(ErrorCode.FunctionImportEntityTypeDoesNotMatchEntitySet, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportEntityTypeDoesNotMatchEntitySet((object)this.FQName, (object)entitySet.EntityType.FQName, (object)entitySet.Name)); } } else { SchemaComplexType schemaComplexType = returnType as SchemaComplexType; if (schemaComplexType != null) { if (entitySet == null && !entitySetPathDefined) { return; } owner.AddError(ErrorCode.ComplexTypeAsReturnTypeAndDefinedEntitySet, EdmSchemaErrorSeverity.Error, owner.LineNumber, owner.LinePosition, (object)Strings.ComplexTypeAsReturnTypeAndDefinedEntitySet((object)this.FQName, (object)schemaComplexType.Name)); } else { if (entitySet == null && !entitySetPathDefined) { return; } owner.AddError(ErrorCode.FunctionImportSpecifiesEntitySetButDoesNotReturnEntityType, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportSpecifiesEntitySetButNotEntityType((object)this.FQName)); } } }
internal static void ValidateRefType(SchemaElement element, SchemaType type) { if (type == null || type is SchemaEntityType) { return; } element.AddError(ErrorCode.ReferenceToNonEntityType, EdmSchemaErrorSeverity.Error, (object)Strings.ReferenceToNonEntityType((object)type.FQName)); }
private bool ValidateUniqueName(SchemaElement end, string name) { if (!this.EndLookup.ContainsKey(name)) { return(true); } end.AddError(ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, (object)Strings.EndNameAlreadyDefinedDuplicate((object)name)); return(false); }
// <summary> // Validated whether a type is declared correctly. // </summary> // <param name="element"> Schema element being validated. Must not be null. </param> // <param name="type"> Resolved type (from declaration on the element). Possibly null. </param> // <param name="typeSubElement"> Child schema element. Possibly null. </param> // <remarks> // For some elements (e.g. ReturnType) we allow the type to be defined inline in an attribute on the element itself or // by using nested elements. These definitions are mutually exclusive. // </remarks> internal static void ValidateTypeDeclaration(SchemaElement element, SchemaType type, SchemaElement typeSubElement) { DebugCheck.NotNull(element); if (type == null && typeSubElement == null) { //Type not declared as either attribute or subelement element.AddError(ErrorCode.TypeNotDeclared, EdmSchemaErrorSeverity.Error, Strings.TypeMustBeDeclared); } if (type != null && typeSubElement != null) { //Both attribute and sub-element declarations exist element.AddError( ErrorCode.TypeDeclaredAsAttributeAndElement, EdmSchemaErrorSeverity.Error, Strings.TypeDeclaredAsAttributeAndElement); } }
private void DuplicateOrEquivalentMemberNameWhileExtendingEntityContainer( SchemaElement schemaElement, AddErrorKind error) { if (error == AddErrorKind.Succeeded) { return; } schemaElement.AddError(ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, (object)Strings.DuplicateMemberNameInExtendedEntityContainer((object)schemaElement.Name, (object)this.ExtendingEntityContainer.Name, (object)this.Name)); }
internal bool ResolveTypeName(SchemaElement usingElement, string typeName, out SchemaType type) { type = (SchemaType)null; string namespaceName1; string name; System.Data.Entity.Core.SchemaObjectModel.Utils.ExtractNamespaceAndName(typeName, out namespaceName1, out name); string alias = namespaceName1 ?? (this.ProviderManifest == null ? this._namespaceName : this.ProviderManifest.NamespaceName); string namespaceName2; if (namespaceName1 == null || !this.AliasResolver.TryResolveAlias(alias, out namespaceName2)) { namespaceName2 = alias; } if (!this.SchemaManager.TryResolveType(namespaceName2, name, out type)) { if (namespaceName1 == null) { usingElement.AddError(ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, (object)Strings.NotNamespaceQualified((object)typeName)); } else if (!this.SchemaManager.IsValidNamespaceName(namespaceName2)) { usingElement.AddError(ErrorCode.BadNamespace, EdmSchemaErrorSeverity.Error, (object)Strings.BadNamespaceOrAlias((object)namespaceName1)); } else if (namespaceName2 != alias) { usingElement.AddError(ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, (object)Strings.NotInNamespaceAlias((object)name, (object)namespaceName2, (object)alias)); } else { usingElement.AddError(ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, (object)Strings.NotInNamespaceNoAlias((object)name, (object)namespaceName2)); } return(false); } if (this.DataModel == SchemaDataModelOption.EntityDataModel || type.Schema == this || type.Schema == this.SchemaManager.PrimitiveSchema) { return(true); } usingElement.AddError(ErrorCode.InvalidNamespaceOrAliasSpecified, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidNamespaceOrAliasSpecified((object)namespaceName1)); return(false); }
protected void AddMember(SchemaElement newMember) { if (string.IsNullOrEmpty(newMember.Name)) { return; } if (this.Schema.DataModel != SchemaDataModelOption.ProviderDataModel && Utils.CompareNames(newMember.Name, this.Name) == 0) { newMember.AddError(ErrorCode.BadProperty, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidMemberNameMatchesTypeName((object)newMember.Name, (object)this.FQName)); } this.NamedMembers.Add(newMember, true, new Func <object, string>(Strings.PropertyNameAlreadyDefinedDuplicate)); }
// <summary> // Validate that reference type is an entity type. // </summary> // <param name="element"> Schema element being validated. Must not be null. </param> // <param name="type"> Resolved type (from declaration on the element). Possibly null. </param> internal static void ValidateRefType(SchemaElement element, SchemaType type) { DebugCheck.NotNull(element); if (type != null && !(type is SchemaEntityType)) { // Ref type refers to non entity type. element.AddError( ErrorCode.ReferenceToNonEntityType, EdmSchemaErrorSeverity.Error, Strings.ReferenceToNonEntityType(type.FQName)); } }
private void ValidateFunctionImportReturnType( SchemaElement owner, SchemaType returnType, CollectionKind returnTypeCollectionKind, EntityContainerEntitySet entitySet, bool entitySetPathDefined) { if (returnType != null && !this.ReturnTypeMeetsFunctionImportBasicRequirements(returnType, returnTypeCollectionKind)) { owner.AddError(ErrorCode.FunctionImportUnsupportedReturnType, EdmSchemaErrorSeverity.Error, owner, (object)this.GetReturnTypeErrorMessage(this.Name)); } this.ValidateFunctionImportReturnType(owner, returnType, entitySet, entitySetPathDefined); }
internal void ResolveEntitySet( SchemaElement owner, string unresolvedEntitySet, ref EntityContainerEntitySet entitySet) { if (entitySet != null || unresolvedEntitySet == null) { return; } entitySet = this._container.FindEntitySet(unresolvedEntitySet); if (entitySet != null) { return; } owner.AddError(ErrorCode.FunctionImportUnknownEntitySet, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportUnknownEntitySet((object)unresolvedEntitySet, (object)this.FQName)); }
private void DuplicateOrEquivalentMemberNameWhileExtendingEntityContainer( SchemaElement schemaElement, AddErrorKind error) { Debug.Assert( error != AddErrorKind.MissingNameError, "Since entity container members are already resolved, name must never be empty"); Debug.Assert(ExtendingEntityContainer != null, "ExtendingEntityContainer must not be null"); if (error != AddErrorKind.Succeeded) { Debug.Assert(error == AddErrorKind.DuplicateNameError, "Error must be duplicate name error"); schemaElement.AddError( ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, Strings.DuplicateMemberNameInExtendedEntityContainer( schemaElement.Name, ExtendingEntityContainer.Name, Name)); } }
internal void ResolveEntitySet(SchemaElement owner, string unresolvedEntitySet, ref EntityContainerEntitySet entitySet) { Debug.Assert(IsFunctionImport, "Only FunctionImport elkements specify EntitySets"); Debug.Assert(null != _container, "function imports must know container"); // resolve entity set if (null == entitySet && null != unresolvedEntitySet) { entitySet = _container.FindEntitySet(unresolvedEntitySet); if (null == entitySet) { owner.AddError( ErrorCode.FunctionImportUnknownEntitySet, EdmSchemaErrorSeverity.Error, Strings.FunctionImportUnknownEntitySet(unresolvedEntitySet, FQName)); } } }
/// <summary> /// Add a member to the type /// </summary> /// <param name="newMember"> the member being added </param> protected void AddMember(SchemaElement newMember) { DebugCheck.NotNull(newMember); if (string.IsNullOrEmpty(newMember.Name)) { // this is an error condition that has already been reported. return; } if (Schema.DataModel != SchemaDataModelOption.ProviderDataModel && Utils.CompareNames(newMember.Name, Name) == 0) { newMember.AddError( ErrorCode.BadProperty, EdmSchemaErrorSeverity.Error, Strings.InvalidMemberNameMatchesTypeName(newMember.Name, FQName)); } NamedMembers.Add(newMember, true, Strings.PropertyNameAlreadyDefinedDuplicate); }
// <summary> // validate the following negative scenarios: // ReturnType="Collection(EntityTypeA)" // ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA" // EntitySet="A" // ReturnType="Collection(ComplexTypeA)" EntitySet="something" // ReturnType="Collection(ComplexTypeA)", but the ComplexTypeA has a nested complexType property, this scenario will be handle in the runtime // </summary> private void ValidateFunctionImportReturnType( SchemaElement owner, SchemaType returnType, EntityContainerEntitySet entitySet, bool entitySetPathDefined) { // If entity type, verify specification of entity set and that the type is appropriate for the entity set var entityType = returnType as SchemaEntityType; if (entitySet != null && entitySetPathDefined) { owner.AddError( ErrorCode.FunctionImportEntitySetAndEntitySetPathDeclared, EdmSchemaErrorSeverity.Error, Strings.FunctionImportEntitySetAndEntitySetPathDeclared(FQName)); } if (null != entityType) { // entity type if (null == entitySet) { // ReturnType="Collection(EntityTypeA)" owner.AddError( ErrorCode.FunctionImportReturnsEntitiesButDoesNotSpecifyEntitySet, EdmSchemaErrorSeverity.Error, Strings.FunctionImportReturnEntitiesButDoesNotSpecifyEntitySet(FQName)); } else if (null != entitySet.EntityType && !entityType.IsOfType(entitySet.EntityType)) { // ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA" owner.AddError( ErrorCode.FunctionImportEntityTypeDoesNotMatchEntitySet, EdmSchemaErrorSeverity.Error, Strings.FunctionImportEntityTypeDoesNotMatchEntitySet( FQName, entitySet.EntityType.FQName, entitySet.Name)); } } else { // complex type var complexType = returnType as SchemaComplexType; if (complexType != null) { if (entitySet != null || entitySetPathDefined) { // ReturnType="Collection(ComplexTypeA)" EntitySet="something" owner.AddError( ErrorCode.ComplexTypeAsReturnTypeAndDefinedEntitySet, EdmSchemaErrorSeverity.Error, owner.LineNumber, owner.LinePosition, Strings.ComplexTypeAsReturnTypeAndDefinedEntitySet(FQName, complexType.Name)); } } else { Debug.Assert( returnType == null || returnType is ScalarType || returnType is SchemaEnumType || returnType is Relationship, "null return type, scalar return type, enum return type or relationship expected here."); // scalar type or no return type if (entitySet != null || entitySetPathDefined) { // EntitySet="A" owner.AddError( ErrorCode.FunctionImportSpecifiesEntitySetButDoesNotReturnEntityType, EdmSchemaErrorSeverity.Error, Strings.FunctionImportSpecifiesEntitySetButNotEntityType(FQName)); } } } }
// <summary> // Look up a fully qualified type name reference. // </summary> // <param name="usingElement"> element containing the reference </param> // <param name="typeName"> the fully qualified type name </param> // <param name="type"> the referenced schema type </param> // <returns> false if there was an error </returns> internal bool ResolveTypeName(SchemaElement usingElement, string typeName, out SchemaType type) { DebugCheck.NotNull(usingElement); DebugCheck.NotNull(typeName); type = null; // get the schema(s) that match the namespace/alias string actualQualification; string unqualifiedTypeName; Utils.ExtractNamespaceAndName(typeName, out actualQualification, out unqualifiedTypeName); var definingQualification = actualQualification; if (definingQualification == null) { definingQualification = ProviderManifest == null ? _namespaceName : ProviderManifest.NamespaceName; } string namespaceName; // First check if there is an alias defined by this name. For primitive type namespace, we do not need to resolve // any alias, since that's a reserved keyword and we don't allow alias with that name if (actualQualification == null || !AliasResolver.TryResolveAlias(definingQualification, out namespaceName)) { namespaceName = definingQualification; } // Resolve the type name if (!SchemaManager.TryResolveType(namespaceName, unqualifiedTypeName, out type)) { // it must be an undefined type. if (actualQualification == null) { // Every type except the primitive type must be qualified usingElement.AddError(ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotNamespaceQualified(typeName)); } else if (!SchemaManager.IsValidNamespaceName(namespaceName)) { usingElement.AddError( ErrorCode.BadNamespace, EdmSchemaErrorSeverity.Error, Strings.BadNamespaceOrAlias(actualQualification)); } else { // if the type name was alias qualified if (namespaceName != definingQualification) { usingElement.AddError( ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotInNamespaceAlias(unqualifiedTypeName, namespaceName, definingQualification)); } else { usingElement.AddError( ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotInNamespaceNoAlias(unqualifiedTypeName, namespaceName)); } } return(false); } // For ssdl and provider manifest, make sure that the type is present in this schema or primitive schema else if (DataModel != SchemaDataModelOption.EntityDataModel && type.Schema != this && type.Schema != SchemaManager.PrimitiveSchema) { Debug.Assert(type.Namespace != Namespace, "Using element is not allowed in the schema of ssdl and provider manifest"); usingElement.AddError( ErrorCode.InvalidNamespaceOrAliasSpecified, EdmSchemaErrorSeverity.Error, Strings.InvalidNamespaceOrAliasSpecified(actualQualification)); return(false); } return(true); }
private void ValidateFunctionImportReturnType( SchemaElement owner, SchemaType returnType, CollectionKind returnTypeCollectionKind, EntityContainerEntitySet entitySet, bool entitySetPathDefined) { if (returnType != null && !ReturnTypeMeetsFunctionImportBasicRequirements(returnType, returnTypeCollectionKind)) { owner.AddError( ErrorCode.FunctionImportUnsupportedReturnType, EdmSchemaErrorSeverity.Error, owner, GetReturnTypeErrorMessage(Name) ); } ValidateFunctionImportReturnType(owner, returnType, entitySet, entitySetPathDefined); }
// <summary> // Look up a fully qualified type name reference. // </summary> // <param name="usingElement"> element containing the reference </param> // <param name="typeName"> the fully qualified type name </param> // <param name="type"> the referenced schema type </param> // <returns> false if there was an error </returns> internal bool ResolveTypeName(SchemaElement usingElement, string typeName, out SchemaType type) { DebugCheck.NotNull(usingElement); DebugCheck.NotNull(typeName); type = null; // get the schema(s) that match the namespace/alias string actualQualification; string unqualifiedTypeName; Utils.ExtractNamespaceAndName(typeName, out actualQualification, out unqualifiedTypeName); var definingQualification = actualQualification; if (definingQualification == null) { definingQualification = ProviderManifest == null ? _namespaceName : ProviderManifest.NamespaceName; } string namespaceName; // First check if there is an alias defined by this name. For primitive type namespace, we do not need to resolve // any alias, since that's a reserved keyword and we don't allow alias with that name if (actualQualification == null || !AliasResolver.TryResolveAlias(definingQualification, out namespaceName)) { namespaceName = definingQualification; } // Resolve the type name if (!SchemaManager.TryResolveType(namespaceName, unqualifiedTypeName, out type)) { // it must be an undefined type. if (actualQualification == null) { // Every type except the primitive type must be qualified usingElement.AddError(ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotNamespaceQualified(typeName)); } else if (!SchemaManager.IsValidNamespaceName(namespaceName)) { usingElement.AddError( ErrorCode.BadNamespace, EdmSchemaErrorSeverity.Error, Strings.BadNamespaceOrAlias(actualQualification)); } else { // if the type name was alias qualified if (namespaceName != definingQualification) { usingElement.AddError( ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotInNamespaceAlias(unqualifiedTypeName, namespaceName, definingQualification)); } else { usingElement.AddError( ErrorCode.NotInNamespace, EdmSchemaErrorSeverity.Error, Strings.NotInNamespaceNoAlias(unqualifiedTypeName, namespaceName)); } } return false; } // For ssdl and provider manifest, make sure that the type is present in this schema or primitive schema else if (DataModel != SchemaDataModelOption.EntityDataModel && type.Schema != this && type.Schema != SchemaManager.PrimitiveSchema) { Debug.Assert(type.Namespace != Namespace, "Using element is not allowed in the schema of ssdl and provider manifest"); usingElement.AddError( ErrorCode.InvalidNamespaceOrAliasSpecified, EdmSchemaErrorSeverity.Error, Strings.InvalidNamespaceOrAliasSpecified(actualQualification)); return false; } return true; }
/// <summary> /// validate the following negative scenarios: /// ReturnType="Collection(EntityTypeA)" /// ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA" /// EntitySet="A" /// ReturnType="Collection(ComplexTypeA)" EntitySet="something" /// ReturnType="Collection(ComplexTypeA)", but the ComplexTypeA has a nested complexType property, this scenario will be handle in the runtime /// </summary> private void ValidateFunctionImportReturnType( SchemaElement owner, SchemaType returnType, EntityContainerEntitySet entitySet, bool entitySetPathDefined) { // If entity type, verify specification of entity set and that the type is appropriate for the entity set var entityType = returnType as SchemaEntityType; if (entitySet != null && entitySetPathDefined) { owner.AddError( ErrorCode.FunctionImportEntitySetAndEntitySetPathDeclared, EdmSchemaErrorSeverity.Error, Strings.FunctionImportEntitySetAndEntitySetPathDeclared(FQName)); } if (null != entityType) { // entity type if (null == entitySet) { // ReturnType="Collection(EntityTypeA)" owner.AddError( ErrorCode.FunctionImportReturnsEntitiesButDoesNotSpecifyEntitySet, EdmSchemaErrorSeverity.Error, Strings.FunctionImportReturnEntitiesButDoesNotSpecifyEntitySet(FQName)); } else if (null != entitySet.EntityType && !entityType.IsOfType(entitySet.EntityType)) { // ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA" owner.AddError( ErrorCode.FunctionImportEntityTypeDoesNotMatchEntitySet, EdmSchemaErrorSeverity.Error, Strings.FunctionImportEntityTypeDoesNotMatchEntitySet( FQName, entitySet.EntityType.FQName, entitySet.Name)); } } else { // complex type var complexType = returnType as SchemaComplexType; if (complexType != null) { if (entitySet != null || entitySetPathDefined) { // ReturnType="Collection(ComplexTypeA)" EntitySet="something" owner.AddError( ErrorCode.ComplexTypeAsReturnTypeAndDefinedEntitySet, EdmSchemaErrorSeverity.Error, owner.LineNumber, owner.LinePosition, Strings.ComplexTypeAsReturnTypeAndDefinedEntitySet(FQName, complexType.Name)); } } else { Debug.Assert( returnType == null || returnType is ScalarType || returnType is SchemaEnumType || returnType is Relationship, "null return type, scalar return type, enum return type or relationship expected here."); // scalar type or no return type if (entitySet != null || entitySetPathDefined) { // EntitySet="A" owner.AddError( ErrorCode.FunctionImportSpecifiesEntitySetButDoesNotReturnEntityType, EdmSchemaErrorSeverity.Error, Strings.FunctionImportSpecifiesEntitySetButNotEntityType(FQName)); } } } }
private bool TryGetFacets(EdmType edmType, bool complainOnMissingFacet, out Dictionary <string, Facet> calculatedFacets) { var noErrors = true; var defaultFacets = edmType.GetAssociatedFacetDescriptions().ToDictionary(f => f.FacetName, f => f.DefaultValueFacet); calculatedFacets = new Dictionary <string, Facet>(); foreach (var defaultFacet in defaultFacets.Values) { object value; if (_facetValues.TryGetValue(defaultFacet.Name, out value)) { // If the facet is a constant facet, then the facet must not be specified in the schema if (defaultFacet.Description.IsConstant) { _element.AddError( ErrorCode.ConstantFacetSpecifiedInSchema, EdmSchemaErrorSeverity.Error, _element, Strings.ConstantFacetSpecifiedInSchema(defaultFacet.Name, edmType.Name)); noErrors = false; } else { calculatedFacets.Add(defaultFacet.Name, Facet.Create(defaultFacet.Description, value)); } // remove the used facet // so we know which ones we need to add below _facetValues.Remove(defaultFacet.Name); } else if (complainOnMissingFacet && defaultFacet.Description.IsRequired) { // Throw missing facet exception _element.AddError( ErrorCode.RequiredFacetMissing, EdmSchemaErrorSeverity.Error, Strings.RequiredFacetMissing( defaultFacet.Name, edmType.Name)); noErrors = false; } else { calculatedFacets.Add(defaultFacet.Name, defaultFacet); } } foreach (var value in _facetValues) { if (value.Key == EdmProviderManifest.StoreGeneratedPatternFacetName) { var facet = Facet.Create(Converter.StoreGeneratedPatternFacet, value.Value); calculatedFacets.Add(facet.Name, facet); } else if (value.Key == EdmProviderManifest.ConcurrencyModeFacetName) { var facet = Facet.Create(Converter.ConcurrencyModeFacet, value.Value); calculatedFacets.Add(facet.Name, facet); } else if (edmType is PrimitiveType && ((PrimitiveType)edmType).PrimitiveTypeKind == PrimitiveTypeKind.String && value.Key == DbProviderManifest.CollationFacetName) { var facet = Facet.Create(Converter.CollationFacet, value.Value); calculatedFacets.Add(facet.Name, facet); } else { _element.AddError( ErrorCode.FacetNotAllowedByType, EdmSchemaErrorSeverity.Error, Strings.FacetNotAllowed(value.Key, edmType.Name)); } } return(noErrors); }