Example #1
0
        public void LoadTableColumns()
        {
            this.TableColumns = GetTableColumns(this.Connectionstring, TableFilters.ToArray <string>());
            foreach (TableInfo t in this.Tables)
            {
                t.Columns = (from c in this.TableColumns
                             where c.TableName == t.Name
                             select c).ToList <TableColumn>();

                t.PKConstraints = (from cn in this.Constraints
                                   where cn.table_name == t.Name &&
                                   cn.constraint_type == "PRIMARY KEY"
                                   select cn).ToList <ConstraintInfo>();

                //load description for columns
                string query = @"select  [value] as [Description],COL_NAME(major_id,minor_id) as ColumnName  
from sys.extended_properties xp   
where xp.class = 1 and  xp.minor_id > 0 and 
xp.major_id = object_id(N'[[schema]].[[table]]') 
and xp.name in (N'MS_Description')"
                               .Replace("[[schema]]", t.SchemaName).Replace("[[table]]", t.Name);
                SqlConnection conn;
                using (IDataReader reader = SqlCommandX.Instance.GetReader(
                           _connectionString, query, CommandType.Text, out conn))
                {
                    while (reader.Read())
                    {
                        var col  = reader["ColumnName"].Text();
                        var desc = reader["Description"].Text();
                        if (col.IsNotNullOrEmpty())
                        {
                            var column = (from c in t.Columns where c.Name.ToLower() == col.ToLower() select c).One();
                            if (column.IsNotNull())
                            {
                                column.Description = desc;
                            }
                        }
                    }
                }
                conn.Destroy();
            }
        }
Example #2
0
 public void LoadConstraints()
 {
     this.Constraints = GetConstraints(this.Connectionstring, TableFilters.ToArray <string>());
 }
Example #3
0
 public void LoadTables()
 {
     this.Tables = GetTables(this.Connectionstring, TableFilters.ToArray <string>()); // load tables
 }