Exemple #1
0
        public override List <DbColumn> GetDbColumns(DataTable dt)
        {
            List <DbColumn> listColumns = new List <DbColumn>();

            List <string> columnsIdentityList = GetSqlServerIdentityColumns(this._tbName);
            List <string> columnPrmaryKey     = new List <string>();// GetSqlServerPrimarykeyColumns(_tbName);

            foreach (DataRow dr in dt.Rows)
            {
                string column_Name = dr["column_name"].ToString();
                string description = dr["description"].ToString();
                string dataType    = (dr["data_type"].ToString());
                if (dataType == "hierarchyid" || dataType == "varbinary" || dataType == "geography")
                {
                    continue;
                }

                Type ColumnType = typeof(string);
                switch (dataType)
                {
                case "bigint": ColumnType = typeof(Int32); break;

                case "int": ColumnType = typeof(Int32); break;

                case "tinyint": ColumnType = typeof(Int32); break;

                case "smallint": ColumnType = typeof(Int32); break;

                case "nvarchar": ColumnType = typeof(string); break;

                case "varchar": ColumnType = typeof(string); break;

                case "decimal": ColumnType = typeof(decimal); break;

                case "numeric": ColumnType = typeof(decimal); break;

                case "real": ColumnType = typeof(decimal); break;

                case "smallmoney": ColumnType = typeof(decimal); break;

                case "datetime": ColumnType = typeof(DateTime); break;

                case "smalldatetime": ColumnType = typeof(DateTime); break;
                // case "timestamp": ColumnType = typeof(DateTime); break;


                case "bit": ColumnType = typeof(Int32); break;

                case "float": ColumnType = typeof(float); break;

                case "nchar": ColumnType = typeof(string); break;

                case "char": ColumnType = typeof(string); break;

                case "ntext": ColumnType = typeof(string); break;

                case "text": ColumnType = typeof(Int32); break;

                case "uniqueidentifier": ColumnType = typeof(Guid); break;

                case "date": ColumnType = typeof(DateTime); break;

                case "money": ColumnType = typeof(decimal); break;
                //case "tinyint": ColumnType = typeof(Int32); break;
                //case "tinyint": ColumnType = typeof(Int32); break;
                //case "tinyint": ColumnType = typeof(Int32); break;
                //case "tinyint": ColumnType = typeof(Int32); break;

                default: ColumnType = typeof(string); break;
                }

                DbColumn column = new DbColumn
                {
                    ColumnName      = column_Name,
                    ColumnType      = ColumnType,
                    Description     = description,
                    IsAutoIncrement = dr["标识"].ToString() == "1",
                    IsPrimaryKey    = dr["主键"].ToString() == "1",
                    DbName          = dr["dbname"].ToString(),
                    TbName          = dr["tableName"].ToString()
                };

                foreach (string item in columnsIdentityList)
                {
                    if (item == column_Name)
                    {
                        column.IsAutoIncrement = true;
                        break;
                    }
                }

                foreach (string item in columnPrmaryKey)
                {
                    if (item == column_Name)
                    {
                        column.IsPrimaryKey = true;
                        break;
                    }
                }
                listColumns.Add(column);
            }
            return(listColumns);
            //  return base.GetDbColumns(dt);
        }
Exemple #2
0
        public override List<DbColumn> GetDbColumns(DataTable dt)
        {
            List<DbColumn> listColumns = new List<DbColumn>();

            List<string> columnsIdentityList = GetSqlServerIdentityColumns(this._tbName);
            List<string> columnPrmaryKey = new List<string>();// GetSqlServerPrimarykeyColumns(_tbName);
            foreach (DataRow dr in dt.Rows)
            {
                string column_Name = dr["column_name"].ToString();
                string description = dr["description"].ToString();
                string dataType = (dr["data_type"].ToString());
                if (dataType == "hierarchyid" || dataType == "varbinary" || dataType == "geography") continue;

                Type ColumnType = typeof(string);
                switch (dataType)
                {
                    case "bigint": ColumnType = typeof(Int32); break;
                    case "int": ColumnType = typeof(Int32); break;
                    case "tinyint": ColumnType = typeof(Int32); break;
                    case "smallint": ColumnType = typeof(Int32); break;

                    case "nvarchar": ColumnType = typeof(string); break;
                    case "varchar": ColumnType = typeof(string); break;
                    case "decimal": ColumnType = typeof(decimal); break;
                    case "numeric": ColumnType = typeof(decimal); break;
                    case "real": ColumnType = typeof(decimal); break;
                    case "smallmoney": ColumnType = typeof(decimal); break;
                    case "datetime": ColumnType = typeof(DateTime); break;
                    case "smalldatetime": ColumnType = typeof(DateTime); break;
                    // case "timestamp": ColumnType = typeof(DateTime); break;


                    case "bit": ColumnType = typeof(Int32); break;
                    case "float": ColumnType = typeof(float); break;
                    case "nchar": ColumnType = typeof(string); break;
                    case "char": ColumnType = typeof(string); break;
                    case "ntext": ColumnType = typeof(string); break;

                    case "text": ColumnType = typeof(Int32); break;
                    case "uniqueidentifier": ColumnType = typeof(Guid); break;

                    case "date": ColumnType = typeof(DateTime); break;
                    case "money": ColumnType = typeof(decimal); break;
                    //case "tinyint": ColumnType = typeof(Int32); break;
                    //case "tinyint": ColumnType = typeof(Int32); break;
                    //case "tinyint": ColumnType = typeof(Int32); break;
                    //case "tinyint": ColumnType = typeof(Int32); break;

                    default: ColumnType = typeof(string); break;
                }

                DbColumn column = new DbColumn
                {
                    ColumnName = column_Name,
                    ColumnType = ColumnType,
                    Description = description,
                    IsAutoIncrement = dr["标识"].ToString() == "1",
                    IsPrimaryKey = dr["主键"].ToString() == "1",
                    DbName = dr["dbname"].ToString(),
                    TbName = dr["tableName"].ToString()
                };

                foreach (string item in columnsIdentityList)
                {
                    if (item == column_Name)
                    {
                        column.IsAutoIncrement = true;
                        break;
                    }
                }

                foreach (string item in columnPrmaryKey)
                {
                    if (item == column_Name)
                    {
                        column.IsPrimaryKey = true;
                        break;
                    }
                }
                listColumns.Add(column);
            }
            return listColumns;
            //  return base.GetDbColumns(dt);
        }