Пример #1
0
        public void AddColumn(IDataContext db, IFieldDescriptor field)
        {
            if (db == null)
            {
                throw new ArgumentNullException("session");
            }

            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            var sqlType = MssqlSqlTypeConverter.GetSqlType(field);
            var sql     = new SqlString("alter table [",
                                        this.Name,
                                        "] add [",
                                        field.Name, "] ", sqlType);

            db.Execute(sql);

            //TODO
            //this.SetColumnComment(db, field);

            if (field.IsUnique)
            {
                this.AddUniqueConstraint(db, field.Name);
            }
        }
Пример #2
0
        public void CreateTable(IDataContext db, IEntityDescriptor model, string label)
        {
            if (db == null)
            {
                throw new ArgumentNullException("session");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var tableName = model.TableName.SqlEscape();

            LoggerProvider.EnvironmentLogger.Debug(String.Format("Creating Table [{0}]...", tableName));

            var fieldsWithoutId = model.Fields.Values.Where(f => f.IsColumn);

            var sb = new SqlStringBuilder();

            sb.Add("create table [");
            sb.Add(tableName);
            sb.Add("] (");

            var commaNeeded = false;

            foreach (var f in fieldsWithoutId)
            {
                if (commaNeeded)
                {
                    sb.Add(", ");
                }
                commaNeeded = true;

                sb.Add("[" + f.Name + "]");
                sb.Add(" ");
                var sqlType = MssqlSqlTypeConverter.GetSqlType(f);
                sb.Add(sqlType);
            }

            sb.Add(") ");

            var sql = sb.ToSqlString();

            db.Execute(sql);

            //TODO 支持表注释
            //SetTableComment(db, tableName, label);
        }