EFIngresProvider/Helpers/MetadataHelpers.cs
/// <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>
Returns the sql primitive/native type name.
It will include size, precision or scale depending on type information present in the
type facets
Returns the sql primitive / native type name . It will include size precision or scale depending on type information present in the type facets
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);
            }
        }
public static string GetSqlPrimitiveType ( TypeUsage type ) { var primitiveType = MetadataHelpers . GetEdmType < PrimitiveType > ( type ) ; switch ( primitiveType . PrimitiveTypeKind ) { case PrimitiveTypeKind . Boolean : return " " ; case PrimitiveTypeKind . Byte : return " " ; case PrimitiveTypeKind . SByte : return " " ; case PrimitiveTypeKind . Int16 : return " " ; case PrimitiveTypeKind . Int32 : return " " ; case PrimitiveTypeKind . Int64 : return " " ; case PrimitiveTypeKind . Single : return " " ; case PrimitiveTypeKind . Double : return " " ; case PrimitiveTypeKind . Time : return " " ; case PrimitiveTypeKind . DateTime : return " " ; case PrimitiveTypeKind . Decimal : var decimalPrecision = MetadataHelpers . GetFacetValueOrDefault < byte > ( type , MetadataHelpers . PrecisionFacetName , 18 ) ; var decimalScale = MetadataHelpers . GetFacetValueOrDefault < byte > ( type , MetadataHelpers . ScaleFacetName , 0 ) ; return string . Format ( " " , 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 ? " " : " " ; if ( isUnicode ) { stringType = " " + stringType ; } if ( isStringLong ) { return " " + stringType ; } return string . Format ( " " , 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 " " ; } return string . Format ( " " , isBinaryFixedLength ? " " : " " , binaryLength ) ; default : throw new NotSupportedException ( " " + primitiveType . PrimitiveTypeKind ) ; } }
Returns the sql primitive/native type name.
Returns the sql primitive / native type name .
None
type
TypeUsage
None