/// <summary>
        /// 复杂版
        /// </summary>
        /// <param Name="TableName"></param>
        /// <returns></returns>
        public static List <DBColumn> getColumns(string tableName)
        {
            List <DBColumn> columns = new List <DBColumn>();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                con.Open();
                using (SqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = @"SELECT 
                                            [TableName] = i_s.TABLE_NAME, 
                                            [ColumnName] = i_s.COLUMN_NAME,
                                            [Description] = s.value ,
                                            [ColumnType] = i_s.DATA_TYPE
                                        FROM 
                                            INFORMATION_SCHEMA.COLUMNS i_s 
                                        LEFT OUTER JOIN 
                                            sysproperties s 
                                        ON 
                                            s.id = OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME) 
                                            AND s.smallid = i_s.ORDINAL_POSITION 
                                            AND s.name = 'MS_Description' 
                                        WHERE 
                                            OBJECTPROPERTY(OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME), 'IsMsShipped')=0 
                                             AND i_s.TABLE_NAME = '" + tableName + @"' 
                                        ORDER BY 
                                            i_s.TABLE_NAME, i_s.ORDINAL_POSITION";
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    DataSet        ds      = new DataSet();
                    adapter.Fill(ds);
                    DataRowCollection rows = ds.Tables[0].Rows;
                    foreach (DataRow row in rows)
                    {
                        DBColumn column = new DBColumn();
                        column.TableName   = row["TableName"].ToString();
                        column.Name        = row["ColumnName"].ToString();
                        column.Description = row["Description"].ToString();
                        column.Type        = SqlServerDbTypeMap.MapCsharpType(row["ColumnType"].ToString());
                        columns.Add(column);
                    }
                }
            }

            return(columns);
        }
Exemple #2
0
        public EntityClassPropertyInfo(EntityInfo entityInfo)
        {
            this.PropertyName       = entityInfo.columnName;
            this.PropertyType       = SqlServerDbTypeMap.MapCsharpType(entityInfo.columnType);//dcol.DataType.Name;
            this.ProptertyComment   = entityInfo.columnComment;
            this.ProptertyMaxLength = entityInfo.columnLength;
            this.ProptertyIsNull    = entityInfo.allowNull;
            this.IsValueType        = false;

            if (entityInfo.allowNull && this.PropertyType != "string")
            {
                this.PropertyType = this.PropertyType + "?";
            }
            else
            {
                this.IsValueType = true;
            }
        }