public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var token = JToken.Load(reader);

            if (token.Type != JTokenType.Array)
            {
                return(null);
            }

            var result = new List <SqlColumnType>();

            foreach (var val in token)
            {
                var colType = new SqlColumnType {
                    Types = new List <int>()
                };

                if (val.Type == JTokenType.Array)
                {
                    colType.Types.AddRange(val.Select(v => v.ToObject <int>()));
                }
                else
                {
                    colType.Types.Add(val.ToObject <int>());
                }

                result.Add(colType);
            }

            return(result);
        }
        public void SerializeValue_ReturnsString_ByDefault()
        {
            var value  = JValue.CreateString("foo");
            var actual = SqlColumnType.SerializeValue(value, "UNDEFINED", JTokenType.String);

            Assert.Equal("foo", actual);
        }
示例#3
0
        public static DbType GetDbType(SqlColumnType type)
        {
            if (!DatabaseHelper.__SqlColumnTypeDbType.ContainsKey(type))
            {
                throw new NotSupportedException();
            }

            return(DatabaseHelper.__SqlColumnTypeDbType[type]);
        }
示例#4
0
 public SqlConstExpression(object value, SqlColumnType type)
 {
     Value = value;
     Type  = type;
 }
示例#5
0
        public static SqlDbType GetDbType(SqlColumnType type)
        {
            switch (type)
            {
            case SqlColumnType.@image:
                return(SqlDbType.Image);

            case SqlColumnType.@text:
                return(SqlDbType.Text);

            case SqlColumnType.@uniqueidentifier:
                return(SqlDbType.UniqueIdentifier);

            case SqlColumnType.@date:
                return(SqlDbType.Date);

            case SqlColumnType.@time:
                return(SqlDbType.Time);

            case SqlColumnType.@datetime2:
                return(SqlDbType.DateTime2);

            case SqlColumnType.@datetimeoffset:
                return(SqlDbType.DateTimeOffset);

            case SqlColumnType.@tinyint:
                return(SqlDbType.TinyInt);

            case SqlColumnType.@smallint:
                return(SqlDbType.SmallInt);

            case SqlColumnType.@int:
                return(SqlDbType.Int);

            case SqlColumnType.@smalldatetime:
                return(SqlDbType.SmallDateTime);

            case SqlColumnType.@real:
                return(SqlDbType.Real);

            case SqlColumnType.@money:
                return(SqlDbType.Money);

            case SqlColumnType.@datetime:
                return(SqlDbType.DateTime);

            case SqlColumnType.@float:
                return(SqlDbType.Float);

            case SqlColumnType.@sql_variant:
                return(SqlDbType.Variant);

            case SqlColumnType.@ntext:
                return(SqlDbType.NText);

            case SqlColumnType.@bit:
                return(SqlDbType.Bit);

            case SqlColumnType.@decimal:
                return(SqlDbType.Decimal);

            case SqlColumnType.@numeric:
                return(SqlDbType.Decimal);

            case SqlColumnType.@smallmoney:
                return(SqlDbType.SmallMoney);

            case SqlColumnType.@bigint:
                return(SqlDbType.BigInt);

            case SqlColumnType.@hierarchyid:
                throw new ArgumentException();

            case SqlColumnType.@geometry:
                throw new ArgumentException();

            case SqlColumnType.@geography:
                throw new ArgumentException();

            case SqlColumnType.@varbinary:
                return(SqlDbType.VarBinary);

            case SqlColumnType.@varchar:
                return(SqlDbType.VarChar);

            case SqlColumnType.@binary:
                return(SqlDbType.Binary);

            case SqlColumnType.@char:
                return(SqlDbType.Char);

            case SqlColumnType.@timestamp:
                return(SqlDbType.Timestamp);

            case SqlColumnType.@nvarchar:
                return(SqlDbType.NVarChar);

            case SqlColumnType.@nchar:
                return(SqlDbType.NChar);

            case SqlColumnType.@xml:
                return(SqlDbType.Xml);

            case SqlColumnType.@sysname:
                throw new ArgumentException();

            default:
                throw new ArgumentException();
            }
        }
示例#6
0
 public ColumnAttribute(string name, SqlDataType dataType = SqlDataType.VarChar, SqlColumnType columnType = 0)
 {
     this.Name       = name;
     this.DataType   = dataType;
     this.ColumnType = columnType;
 }
 public SqlColumnDefinition(SqlTableDefinition owner, string name, SqlColumnType type)
 {
     Owner = owner;
     Name  = name;
     Type  = type;
 }
 public void SerializeValue_Null_ReturnsNull()
 {
     Assert.Null(SqlColumnType.SerializeValue(null, "STRING", JTokenType.String));
     Assert.Null(SqlColumnType.SerializeValue(JValue.CreateNull(), "STRING", JTokenType.String));
 }
 public void IsFloatType_Works(string type, bool expected)
 {
     Assert.Equal(expected, SqlColumnType.IsFloatType(type));
 }
 public void GetStoreCaseType_Throws(Type sut)
 {
     Assert.Throws <NotSupportedException>(() => SqlColumnType.GetStoreCastType(sut));
 }
 public void GetStoreCaseType_Works(Type sut, string expected)
 {
     Assert.Equal(expected, SqlColumnType.GetStoreCastType(sut));
 }
 public void Get_WithNull_Works()
 {
     Assert.Null(SqlColumnType.Get(JTokenType.Null, true));
     Assert.Throws <NotSupportedException>(() => SqlColumnType.Get(JTokenType.Null, false));
 }