Пример #1
0
 /// <summary>
 /// Retrieves the properties of in the EdmType underlying the input type usage,
 ///  if that EdmType is a structured type (EntityType, RowType).
 /// </summary>
 /// <param name="typeUsage"></param>
 /// <returns></returns>
 internal static IList <EdmProperty> GetProperties(TypeUsage typeUsage)
 {
     return(MetadataHelpers.GetProperties(typeUsage.EdmType));
 }
Пример #2
0
 internal static bool IsFacetValueConstant(TypeUsage type, string facetName)
 {
     return(MetadataHelpers.GetFacet(((PrimitiveType)type.EdmType).FacetDescriptions, facetName).IsConstant);
 }
Пример #3
0
 /// <summary>
 /// Is the given type usage over an entity type
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 internal static bool IsEntityType(TypeUsage type)
 {
     return(MetadataHelpers.IsEntityType(type.EdmType));
 }
Пример #4
0
        /// <summary>
        /// Returns the sql primitive/native type name.
        /// It will include size, precision or scale depending on type information present in the
        /// type facets
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string GetSqlPrimitiveType(TypeUsage type)
        {
            var primitiveType = MetadataHelpers.GetEdmType <PrimitiveType>(type);

            switch (primitiveType.PrimitiveTypeKind)
            {
            case PrimitiveTypeKind.Boolean:
                return("tinyint");

            case PrimitiveTypeKind.Byte:
                return("tinyint");

            case PrimitiveTypeKind.SByte:
                return("smallint");

            case PrimitiveTypeKind.Int16:
                return("smallint");

            case PrimitiveTypeKind.Int32:
                return("integer");

            case PrimitiveTypeKind.Int64:
                return("bigint");

            case PrimitiveTypeKind.Single:
                return("real");

            case PrimitiveTypeKind.Double:
                return("float");

            case PrimitiveTypeKind.Time:
                return("time");

            case PrimitiveTypeKind.DateTime:
                return("ingresdate");

            case PrimitiveTypeKind.Decimal:
                var decimalPrecision = MetadataHelpers.GetFacetValueOrDefault <byte>(type, MetadataHelpers.PrecisionFacetName, 18);
                var decimalScale     = MetadataHelpers.GetFacetValueOrDefault <byte>(type, MetadataHelpers.ScaleFacetName, 0);
                return(string.Format("decimal({0}, {1})", decimalPrecision, decimalScale));

            case PrimitiveTypeKind.String:
                var isUnicode           = MetadataHelpers.GetFacetValueOrDefault <bool>(type, MetadataHelpers.UnicodeFacetName, false);
                var isStringFixedLength = MetadataHelpers.GetFacetValueOrDefault <bool>(type, MetadataHelpers.FixedLengthFacetName, false);
                var stringLength        = MetadataHelpers.GetFacetValueOrDefault <int?>(type, MetadataHelpers.MaxLengthFacetName, 4000);
                var isStringLong        = (stringLength == null) || (isUnicode && !isStringFixedLength && (stringLength > 4000)) || (!isUnicode && !isStringFixedLength && (stringLength > 8000));
                var stringType          = isStringFixedLength && !isStringLong ? "char" : "varchar";
                if (isUnicode)
                {
                    stringType = "n" + stringType;
                }
                if (isStringLong)
                {
                    return("long " + stringType);
                }
                return(string.Format("{0}({1})", stringType, stringLength));

            case PrimitiveTypeKind.Binary:
                var isBinaryFixedLength = MetadataHelpers.GetFacetValueOrDefault <bool>(type, MetadataHelpers.FixedLengthFacetName, false);
                var binaryLength        = MetadataHelpers.GetFacetValueOrDefault <int?>(type, MetadataHelpers.MaxLengthFacetName, null);
                var isBinaryLong        = (binaryLength == null) || (!isBinaryFixedLength && (binaryLength > 8000));
                if (isBinaryLong)
                {
                    return("long byte");
                }
                return(string.Format("byte{0}({1})", isBinaryFixedLength ? " varying" : "", binaryLength));

            default:
                throw new NotSupportedException("Unsupported EdmType: " + primitiveType.PrimitiveTypeKind);
            }
        }
Пример #5
0
 /// <summary>
 /// Is the given type usage over a primitive type
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 internal static bool IsPrimitiveType(TypeUsage type)
 {
     return(MetadataHelpers.IsPrimitiveType(type.EdmType));
 }