public static void VerifyFacetDescriptionsEquivalent( FacetDescription facetDescription, LegacyMetadata.FacetDescription legacyFacetDescription) { Assert.Equal(facetDescription.FacetName, legacyFacetDescription.FacetName); VerifyEdmTypesEquivalent(legacyFacetDescription.FacetType, facetDescription.FacetType); Assert.True( // .ToString makes it easier to compare default values like "Variable" facetDescription.DefaultValue.ToString() == legacyFacetDescription.DefaultValue.ToString() || facetDescription.DefaultValue == legacyFacetDescription.DefaultValue); Assert.Equal(facetDescription.IsConstant, legacyFacetDescription.IsConstant); Assert.Equal(facetDescription.IsRequired, legacyFacetDescription.IsRequired); Assert.Equal(facetDescription.MaxValue, legacyFacetDescription.MaxValue); Assert.Equal(facetDescription.MinValue, legacyFacetDescription.MinValue); }
internal override void Configure(EdmProperty column, FacetDescription facetDescription) { switch (facetDescription.FacetName) { case XmlConstants.FixedLengthElement: column.IsFixedLength = facetDescription.IsConstant ? null : IsFixedLength ?? column.IsFixedLength; break; case XmlConstants.MaxLengthElement: column.MaxLength = facetDescription.IsConstant ? null : MaxLength ?? column.MaxLength; column.IsMaxLength = !facetDescription.IsConstant && (IsMaxLength ?? column.IsMaxLength); break; } }
private bool ValidateInterFacetConsistency() { if (this.PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Decimal) { FacetDescription facet1 = Helper.GetFacet(this.FacetDescriptions, "Precision"); FacetDescription facet2 = Helper.GetFacet(this.FacetDescriptions, "Scale"); if (facet1.MaxValue.Value < facet2.MaxValue.Value) { this.AddError(ErrorCode.BadPrecisionAndScale, EdmSchemaErrorSeverity.Error, (object)Strings.BadPrecisionAndScale((object)facet1.MaxValue.Value, (object)facet2.MaxValue.Value)); return(false); } } return(true); }
internal override void Configure(EdmProperty column, FacetDescription facetDescription) { base.Configure(column, facetDescription); switch (facetDescription.FacetName) { case XmlConstants.PrecisionElement: column.Precision = facetDescription.IsConstant ? null : Precision ?? column.Precision; break; case XmlConstants.ScaleElement: column.Scale = facetDescription.IsConstant ? null : Scale ?? column.Scale; break; } }
internal override void Configure(EdmProperty column, FacetDescription facetDescription) { base.Configure(column, facetDescription); switch (facetDescription.FacetName) { case "FixedLength": EdmProperty edmProperty1 = column; bool? nullable1; if (!facetDescription.IsConstant) { bool?isFixedLength = this.IsFixedLength; nullable1 = isFixedLength.HasValue ? new bool?(isFixedLength.GetValueOrDefault()) : column.IsFixedLength; } else { nullable1 = new bool?(); } edmProperty1.IsFixedLength = nullable1; break; case "MaxLength": EdmProperty edmProperty2 = column; int? nullable2; if (!facetDescription.IsConstant) { int?maxLength = this.MaxLength; nullable2 = maxLength.HasValue ? new int?(maxLength.GetValueOrDefault()) : column.MaxLength; } else { nullable2 = new int?(); } edmProperty2.MaxLength = nullable2; EdmProperty edmProperty3 = column; int num; if (!facetDescription.IsConstant) { bool?isMaxLength = this.IsMaxLength; num = isMaxLength.HasValue ? (isMaxLength.GetValueOrDefault() ? 1 : 0) : (column.IsMaxLength ? 1 : 0); } else { num = 0; } edmProperty3.IsMaxLength = num != 0; break; } }
private void ValidateSpatialFacets(EdmType type, Dictionary <string, Facet> facets) { PrimitiveType primitiveType = (PrimitiveType)type; Debug.Assert(Helper.IsSpatialType(primitiveType), "Expected spatial type"); if (_facetValues.ContainsKey(EdmProviderManifest.ConcurrencyModeFacetName)) { _element.AddError(ErrorCode.FacetNotAllowedByType, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.FacetNotAllowed(EdmProviderManifest.ConcurrencyModeFacetName, type.FullName)); } Facet isStrictFacet; if (this._element.Schema.DataModel == SchemaDataModelOption.EntityDataModel && (!facets.TryGetValue(EdmProviderManifest.IsStrictFacetName, out isStrictFacet) || (bool)isStrictFacet.Value != false)) { _element.AddError(ErrorCode.UnexpectedSpatialType, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.SpatialWithUseStrongSpatialTypesFalse); } // Validate the srid facet, if specified Facet sridFacet; //here we are assuming if the facet should be here or not is already get checked before if (!facets.TryGetValue(EdmProviderManifest.SridFacetName, out sridFacet) || sridFacet.Value == null) { return; } if (Helper.IsVariableFacetValue(sridFacet)) { return; } int srid = (int)sridFacet.Value; FacetDescription facetDescription = Helper.GetFacet(primitiveType.FacetDescriptions, EdmProviderManifest.SridFacetName); int maxSrid = (int)facetDescription.MaxValue; int minSrid = (int)facetDescription.MinValue; if (srid < minSrid || srid > maxSrid) { _element.AddError(ErrorCode.InvalidSystemReferenceId, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidSystemReferenceId(srid, minSrid, maxSrid, primitiveType.Name)); } }
/// <summary> /// Tries to get the name of a facet starting from an EdmType. /// </summary> /// <param name="edmType">Type of the edm.</param> /// <param name="facetName">Name of the facet.</param> /// <param name="facetDescription">The facet description.</param> /// <returns>True if the facet was found; otherwise false</returns> public static bool TryGetTypeFacetDescriptionByName(this EdmType edmType, string facetName, out FacetDescription facetDescription) { facetDescription = null; if (MetadataHelpers.IsPrimitiveType(edmType)) { var primitiveType = (PrimitiveType)edmType; foreach (var fd in primitiveType.FacetDescriptions) { if (facetName.Equals(fd.FacetName, StringComparison.OrdinalIgnoreCase)) { facetDescription = fd; return(true); } } } return(false); }
private bool ValidateInterFacetConsistency() { if (PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Decimal) { FacetDescription precisionFacetDescription = Helper.GetFacet(FacetDescriptions, EdmProviderManifest.PrecisionFacetName); FacetDescription scaleFacetDescription = Helper.GetFacet(FacetDescriptions, EdmProviderManifest.ScaleFacetName); if (precisionFacetDescription.MaxValue.Value < scaleFacetDescription.MaxValue.Value) { AddError(ErrorCode.BadPrecisionAndScale, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.BadPrecisionAndScale( precisionFacetDescription.MaxValue.Value, scaleFacetDescription.MaxValue.Value)); return(false); } } return(true); }
private void ValidateLengthFacets(EdmType type, Dictionary <string, Facet> facets) { PrimitiveType primitiveType = (PrimitiveType)type; Facet facet1; if (!facets.TryGetValue("MaxLength", out facet1) || facet1.Value == null || Helper.IsUnboundedFacetValue(facet1)) { return; } int num1 = (int)facet1.Value; FacetDescription facet2 = Helper.GetFacet((IEnumerable <FacetDescription>)primitiveType.FacetDescriptions, "MaxLength"); int num2 = facet2.MaxValue.Value; int num3 = facet2.MinValue.Value; if (num1 >= num3 && num1 <= num2) { return; } this._element.AddError(ErrorCode.InvalidSize, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidSize((object)num1, (object)num3, (object)num2, (object)primitiveType.Name)); }
internal override void Configure(EdmProperty column, FacetDescription facetDescription) { base.Configure(column, facetDescription); switch (facetDescription.FacetName) { case "Precision": EdmProperty edmProperty = column; byte? nullable; if (!facetDescription.IsConstant) { byte?precision = this.Precision; nullable = precision.HasValue ? new byte?(precision.GetValueOrDefault()) : column.Precision; } else { nullable = new byte?(); } edmProperty.Precision = nullable; break; } }
internal override void Configure(EdmProperty column, FacetDescription facetDescription) { base.Configure(column, facetDescription); switch (facetDescription.FacetName) { case "Unicode": EdmProperty edmProperty = column; bool? nullable; if (!facetDescription.IsConstant) { bool?isUnicode = this.IsUnicode; nullable = isUnicode.HasValue ? new bool?(isUnicode.GetValueOrDefault()) : column.IsUnicode; } else { nullable = new bool?(); } edmProperty.IsUnicode = nullable; break; } }
internal virtual void Configure(EdmProperty column, FacetDescription facetDescription) { DebugCheck.NotNull(column); DebugCheck.NotNull(facetDescription); }
internal void CreateAndValidateFacetDescription(string declaringTypeName) { this._facetDescription = new FacetDescription(this.Name, this.FacetType, this.MinValue, this.MaxValue, this.DefaultValue, this._isConstant, declaringTypeName); }
internal static FacetDescription[] GetInitialFacetDescriptions(PrimitiveTypeKind primitiveTypeKind) { FacetDescription[] list; switch (primitiveTypeKind) { case PrimitiveTypeKind.String: { list = new FacetDescription[3]; list[0] = (new FacetDescription( MaxLengthFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Int32), 0, Int32.MaxValue, null)); list[1] = (new FacetDescription( UnicodeFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean), null, null, null)); list[2] = (new FacetDescription( FixedLengthFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean), null, null, null)); return list; } case PrimitiveTypeKind.Binary: { list = new FacetDescription[2]; list[0] = (new FacetDescription( MaxLengthFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Int32), 0, Int32.MaxValue, null)); list[1] = (new FacetDescription( FixedLengthFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean), null, null, null)); return list; } case PrimitiveTypeKind.DateTime: { list = new FacetDescription[1]; list[0] = (new FacetDescription( PrecisionFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte), 0, MaximumDateTimePrecision, null)); return list; } case PrimitiveTypeKind.Time: { list = new FacetDescription[1]; list[0] = (new FacetDescription( PrecisionFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte), 0, MaximumDateTimePrecision, TypeUsage.DefaultDateTimePrecisionFacetValue)); return list; } case PrimitiveTypeKind.DateTimeOffset: { list = new FacetDescription[1]; list[0] = (new FacetDescription( PrecisionFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte), 0, MaximumDateTimePrecision, TypeUsage.DefaultDateTimePrecisionFacetValue)); return list; } case PrimitiveTypeKind.Decimal: { list = new FacetDescription[2]; list[0] = (new FacetDescription( PrecisionFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte), 1, MaximumDecimalPrecision, null)); list[1] = (new FacetDescription( ScaleFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte), 0, MaximumDecimalPrecision, null)); return list; } case PrimitiveTypeKind.Geometry: case PrimitiveTypeKind.GeometryPoint: case PrimitiveTypeKind.GeometryLineString: case PrimitiveTypeKind.GeometryPolygon: case PrimitiveTypeKind.GeometryMultiPoint: case PrimitiveTypeKind.GeometryMultiLineString: case PrimitiveTypeKind.GeometryMultiPolygon: case PrimitiveTypeKind.GeometryCollection: { list = new FacetDescription[2]; list[0] = (new FacetDescription( SridFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Int32), 0, Int32.MaxValue, DbGeometry.DefaultCoordinateSystemId)); list[1] = (new FacetDescription( IsStrictFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean), null, null, true)); return list; } case PrimitiveTypeKind.Geography: case PrimitiveTypeKind.GeographyPoint: case PrimitiveTypeKind.GeographyLineString: case PrimitiveTypeKind.GeographyPolygon: case PrimitiveTypeKind.GeographyMultiPoint: case PrimitiveTypeKind.GeographyMultiLineString: case PrimitiveTypeKind.GeographyMultiPolygon: case PrimitiveTypeKind.GeographyCollection: { list = new FacetDescription[2]; list[0] = (new FacetDescription( SridFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Int32), 0, Int32.MaxValue, DbGeography.DefaultCoordinateSystemId)); list[1] = (new FacetDescription( IsStrictFacetName, MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean), null, null, true)); return list; } default: return null; } }
internal virtual void Configure(EdmProperty column, FacetDescription facetDescription) { }
internal void CreateAndValidateFacetDescription(string declaringTypeName) { _facetDescription = new FacetDescription(Name, FacetType, MinValue, MaxValue, DefaultValue, _isConstant, declaringTypeName); }
internal static bool TryGetTypeFacetDescriptionByName(EdmType edmType, string facetName, out FacetDescription facetDescription) { facetDescription = null; var primitiveType = edmType as PrimitiveType; if (null != primitiveType) { foreach (var fd in primitiveType.FacetDescriptions) { if (facetName.Equals(fd.FacetName, StringComparison.OrdinalIgnoreCase)) { facetDescription = fd; return(true); } } } return(false); }