Exemplo n.º 1
0
        /// <summary>
        ///     子表遍历
        /// </summary>
        /// <param name="cols"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public string ForEach(TableKeySchemaCollection cols, string format)
        {
            var sb = new StringBuilder();
            foreach (var col in cols)
            {
                var parentTable = col.PrimaryKeyTable;
                var childrenTable = col.ForeignKeyTable;

                var tagTable = parentTable.Equals(CurrentTable) ? childrenTable : parentTable;
                var m = new DataModel
                {
                    ChildrenTableName = DbUtil.GetTableName(tagTable.Name, CutFirstTableName),
                };

                m.ChildrenTableComment = DbUtil.GetComment(tagTable.Description, m.ChildrenTableName);

                m.PerentTableName = m.ChildrenTableName;
                m.ParentTableComment = m.ChildrenTableComment;

                sb.AppendLine(DbUtil.Format(format, m));
            }
            return sb.ToString();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 格式化输出,根据模板特定的字段输出
        /// </summary>
        /// <param name="format"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        public static string Format(string format, DataModel m)
        {
            format = format.Replace("table.name", m.TableName);
            format = format.Replace("table.comment", m.TableComment);

            format = format.Replace("fk.name", m.PerentTableName);
            format = format.Replace("fk.comment", m.ParentTableComment);

            format = format.Replace("col.name", m.ColumnName);
            format = format.Replace("col.dbname", m.ColumnDbName);
            format = format.Replace("col.type", m.ColumnTypeNotNull);
            format = format.Replace("col.nulltype", m.ColumnType);
            format = format.Replace("col.comment", m.ColumnComment);
            format = format.Replace("col.dbtype", m.ColumnDbType);
            format = format.Replace("col.length", m.ColumnLength);
            format = format.Replace("col.default", m.ColumnDefaultValue);
            format = format.Replace("col.isidentity", m.ColumnIdentity.ToString().ToLower());
            format = format.Replace("col.enableNull", m.ColumnEnableNull.ToString().ToLower());
            format = format.Replace("col.isPrimarykey", m.ColumnIsPrimarykey.ToString().ToLower());

            return format;
        }
Exemplo n.º 3
0
        /// <summary>
        ///     遍历列
        /// </summary>
        /// <param name="cols">列集合</param>
        /// <param name="format">模板</param>
        /// <returns></returns>
        public string ForEach(ColumnSchemaCollection cols, string format)
        {
            var sb = new StringBuilder();
            foreach (var col in cols)
            {

                var isPrimaryKeyMember = col.IsPrimaryKeyMember; // 是否为主键列
                var m = new DataModel
                {
                    TableComment = DbUtil.GetComment(CurrentTable.Description, TableName),
                    ColumnName = DbUtil.GetColumnName(col.Name, CutColumnName),
                    ColumnDbType = col.NativeType,
                    ColumnDbName = col.Name,
                    ColumnIsPrimarykey = col.IsPrimaryKeyMember,
                    ColumnTypeNotNull = DbUtil.GetColumnType(col.SystemType),
                    ColumnType = DbUtil.GetColumnType(col.SystemType),
                    ColumnLength = (col.Size < 0 ? int.MaxValue : col.Size).ToString(CultureInfo.InvariantCulture),
                    ColumnEnableNull = col.AllowDBNull,
                    ColumnIdentity = Convert.ToBoolean(col.ExtendedProperties["CS_IsIdentity"].Value.ToString()),
                    ColumnDefaultValue = col.ExtendedProperties["CS_Default"].Value.ToString(),
                    TableName = TableName
                };
                m.ColumnComment = col.Description;
                m.ColumnComment = DbUtil.GetComment(col.Description, m.ColumnName);
                if (isPrimaryKeyMember)
                    m.ColumnComment += "主键列";

                m.ColumnType = m.ColumnEnableNull ? m.ColumnType + "?" : m.ColumnType;

                sb.AppendLine(DbUtil.Format(format, m));
            }
            return sb.ToString();
        }