Exemple #1
0
        /// <inheritdoc/>
        public TableDataModel GetTable(TableViewModel table)
        {
            using (var connection = new SqlConnection(config.ConnectionString))
            {
                connection.Open();
                var adapter = new SqlDataAdapter(new SqlCommand(SqlExpression.GetTableInfoExpression, connection));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@p1", table.Name));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@p2", table.Schema));
                var set = new DataSet();
                adapter.Fill(set);
                var columns = new Dictionary <string, ColumnTypes>();
                using (var reader = set.CreateDataReader())
                {
                    while (reader.Read())
                    {
                        columns.Add(reader.GetString(0), EnumConverter.ConvertToColumnType(reader.GetString(1)));
                    }
                    reader.Close();
                }
                connection.Close();

                return(new TableDataModel()
                {
                    TableId = table.Id,
                    Name = $"{table.Schema}.{table.Name}",
                    Columns = columns.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value)
                });
            }
        }