コード例 #1
0
        protected SqlBuilder GetColumnSqlType(Column column, string defaultValuePostfix = "")
        {
            if (column.Type == null)
                throw new ArgumentException($"Column {column.Name} must have a type");

            var sql = new SqlBuilder();

            var sqlColumn = SqlTypeMap.Convert(column);
            sql.Append(new SqlParameter { DbType = sqlColumn.DbType }.SqlDbType.ToString());
            sql.Append(sqlColumn.Length != null, "(" + sqlColumn.Length + ")");
            sql.Append(column.Nullable, "NULL").Or("NOT NULL");
            sql.Append(column.DefaultValue != null, "DEFAULT '{0}'", column.DefaultValue);
            sql.Append(column.IsPrimaryKey, " PRIMARY KEY");

            return sql;
        }