예제 #1
0
    public static SqlTypeNumberBase FromPrecisionAndScale(string typeName, int precision, int?scale)
    {
        var sqlTypeNumberBase = new SqlTypeNumberBase(typeName);
        var scale2            = scale ?? 0;
        var range             = DoubleTypeRangeCalculator.CalculateRange(precision, scale2);

        if (typeName.InsensitiveEquals("decimal"))
        {
            try
            {
                range.UpperBound = (double)(decimal)range.UpperBound;
            }
            catch (Exception)
            {
                range.UpperBound = (double)decimal.MaxValue;
            }
            try
            {
                range.LowerBound = (double)(decimal)range.LowerBound;
            }
            catch (Exception)
            {
                range.LowerBound = (double)decimal.MinValue;
            }
        }

        sqlTypeNumberBase.UpperBound       = range.UpperBound;
        sqlTypeNumberBase.LowerBound       = range.LowerBound;
        sqlTypeNumberBase.NumericPrecision = precision;
        sqlTypeNumberBase.NumericScale     = scale2;
        return(sqlTypeNumberBase);
    }
예제 #2
0
    public static SqlTypeNumberBase FromBounds(string typeName, double lowerBound, double upperBound)
    {
        var sqlTypeNumberBase = new SqlTypeNumberBase(typeName);

        sqlTypeNumberBase.LowerBound = lowerBound;
        sqlTypeNumberBase.UpperBound = upperBound;
        return(sqlTypeNumberBase);
    }
    public void TestDataAnnotationDefinitionNumericRange()
    {
        var sqlColumn = new SqlColumn()
        {
            SqlDataType = SqlTypeNumberBase.FromBounds("int", 100, 200),
            IsNullable  = true,
            Name        = "PropertyName"
        };

        var cSharpProperty = CSharpPropertyFactoryFromSqlColumn.ToCSharpProperty(sqlColumn);

        Console.WriteLine(cSharpProperty);
    }
예제 #4
0
    public static SqlTypeNumberBase Decimal(int precision, int?scale = 0)
    {
        if (precision is < 1 or > 38)
        {
            throw new ArgumentException("Precision must be between 1 and 38 inclusive", nameof(precision));
        }

        if (scale.HasValue && (scale < 0 || scale > precision))
        {
            throw new ArgumentException("Scale, if provided, must be between 0 and 38 inclusive", nameof(scale));
        }

        return(SqlTypeNumberBase.FromPrecisionAndScale("decimal", precision, scale));
    }
예제 #5
0
 public static SqlTypeNumberBase SmallMoney()
 {
     return(SqlTypeNumberBase.FromBounds("smallmoney", -214748.3648, 214748.3647));
 }
예제 #6
0
 public static SqlTypeNumberBase Money()
 {
     return(SqlTypeNumberBase.FromBounds("money", -922337203685477.5808, 922337203685477.5807));
 }
예제 #7
0
 public static SqlTypeNumberBase BigInt()
 {
     return(SqlTypeNumberBase.FromBounds("bigint", bigIntLowerBound, bigIntUpperBound));
 }
예제 #8
0
 public static SqlTypeNumberBase Int()
 {
     return(SqlTypeNumberBase.FromBounds("int", int.MinValue, int.MaxValue));
 }
예제 #9
0
 public static SqlTypeNumberBase SmallInt()
 {
     return(SqlTypeNumberBase.FromBounds("smallint", -32768, 32767));
 }
예제 #10
0
 public static SqlTypeNumberBase TinyInt()
 {
     return(SqlTypeNumberBase.FromBounds("tinyint", 0, 255));
 }