Beispiel #1
0
        public void Column(string column_name, DbType type, object options)
        {
            var attrs = AttributesHelper.Parse(options);
            var opts = new { Default = attrs.GetValueOrDefault("Default", (string)null), Limit = attrs.GetValueOrDefault("Limit", 255), Precision = attrs.GetValueOrDefault("Precision", (int?)null), Scale = attrs.GetValueOrDefault("Scale", (int?)null), Null = attrs.GetValueOrDefault("Null", true) };

            var column = new ColumnDefinition { Name = column_name, Type = type, Default = opts.Default, Limit = opts.Limit, Precision = opts.Precision, Scale = opts.Scale, Null = opts.Null };
            Columns.Add(column);
        }
Beispiel #2
0
        public void AddColumn(string tableName, string columnName, DbType type, object options)
        {
            var attrs = AttributesHelper.Parse(options);
            var opts = new { Default = attrs.GetValueOrDefault("Default", (object)null), Limit = attrs.GetValueOrDefault("Limit", 255), Null = attrs.GetValueOrDefault("Null", true), AutoIncrement = attrs.GetValueOrDefault("AutoIncrement", false), Scale = attrs.GetValueOrDefault("Scale", (int?)null), Precision = attrs.GetValueOrDefault("Precision", (int?)null) };

            var column = new ColumnDefinition { Name = columnName, AutoIncrement = opts.AutoIncrement, Default = opts.Default, Limit = opts.Limit, Null = opts.Null, Precision = opts.Precision, Scale = opts.Scale, Type = type };

            var sql = string.Format("ALTER TABLE {0} ADD COLUMN {1}", tableName, column.ToSql());
            Console.WriteLine(sql);
            Configuration.DatabaseProvider.ExecuteNonQuery(sql);
        }