예제 #1
0
파일: Table.cs 프로젝트: Daoting/dt
        /// <summary>
        /// 根据表名创建空Table
        /// </summary>
        /// <param name="p_tblName">表名</param>
        /// <returns></returns>
        public static Table Create(string p_tblName)
        {
            Throw.IfNullOrEmpty(p_tblName);
            Table tbl = new Table();

#if SERVER
            var schema = DbSchema.GetTableSchema(p_tblName);
            foreach (var col in schema.PrimaryKey.Concat(schema.Columns))
            {
                tbl._columns.Add(new Column(col.Name, col.Type));
            }
#else
            foreach (var col in AtModel.EachColumns(p_tblName))
            {
                tbl._columns.Add(new Column(col.ColName, GetColType(col.DbType)));
            }
#endif
            return(tbl);
        }
예제 #2
0
        internal static TableSchema GetTableSchema(string p_tblName)
        {
            TableSchema schema = new TableSchema(p_tblName.ToLower());

            foreach (var oc in AtModel.EachColumns(p_tblName.ToLower()))
            {
                TableCol col = new TableCol();
                col.Name     = oc.ColName;
                col.Type     = Table.GetColType(oc.DbType);
                col.Length   = oc.Length;
                col.Nullable = oc.Nullable;
                col.Comments = oc.Comments;
                if (oc.IsPrimary)
                {
                    schema.PrimaryKey.Add(col);
                }
                else
                {
                    schema.Columns.Add(col);
                }
            }
            return(schema);
        }