private List <Table> GetSqlServerTables(string connectionString)
        {
            List <Table> tableList = new List <Table>();

            try
            {
                DataTable dt = new DataTable();
                dt = generatorDL.GetSqlServerTables(connectionString);
                List <string> tables = DbDataUtil.GetColumnAsUniqueList(dt, "TABLE_NAME");
                DataRow[]     rows;
                List <Column> columns;
                Table         tbl;

                foreach (string strTable in tables)
                {
                    tbl = new Table()
                    {
                        TableName = strTable
                    };
                    columns = new List <Column>();
                    rows    = dt.Select(string.Format("TABLE_NAME='{0}'", strTable));
                    foreach (DataRow rw in rows)
                    {
                        //columns.Add(new Column(rw["COLUMN_NAME"].ToString(), rw["DATA_TYPE"].ToString()));
                        Column cl = rw.RowToObject <Column>(dt.Columns);
                        columns.Add(cl);
                        if (cl.IdentityState == 1 && string.IsNullOrWhiteSpace(tbl.IdColumn))
                        {
                            tbl.IdColumn = cl.ColumnName;
                        }
                    }

                    tbl.TableColumns = columns;

                    /*
                     * rows = null;
                     * rows = dt.Select(string.Format("TABLE_NAME='{0}' AND IdentityState=1", strTable));
                     *
                     * foreach (DataRow rw2 in rows)
                     * {
                     *  tbl.IdColumn = rw2["COLUMN_NAME"].ToString();
                     *  break;
                     * }
                     */
                    tableList.Add(tbl);
                }
            }
            catch (Exception e)
            {
                throw;
            }

            return(tableList);
        }
Exemple #2
0
        private List <Table> GetSqlServerTables(string connectionString)
        {
            List <Table> tableList = new List <Table>();

            try
            {
                DataTable dt = new DataTable();
                dt = generatorDL.GetSqlServerTables(connectionString);
                List <string> tables = DbDataUtil.GetColumnAsUniqueList(dt, "TABLE_NAME");
                DataRow[]     rows;
                List <Column> columns;
                Table         tbl;
                foreach (string strTable in tables)
                {
                    tbl = new Table()
                    {
                        TableName = strTable
                    };
                    columns = new List <Column>();
                    rows    = dt.Select(string.Format("TABLE_NAME='{0}'", strTable));
                    foreach (DataRow rw in rows)
                    {
                        columns.Add(new Column(rw["COLUMN_NAME"].ToString(), rw["DATA_TYPE"].ToString()));
                    }

                    tbl.TableColumns = columns;

                    rows = null;
                    rows = dt.Select(string.Format("TABLE_NAME='{0}' AND IdentityState=1", strTable));

                    foreach (DataRow rw2 in rows)
                    {
                        tbl.IdColumn = rw2["COLUMN_NAME"].ToString();
                        break;
                    }

                    tableList.Add(tbl);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(tableList);
        }