Ejemplo n.º 1
0
        /// <summary>
        /// enumerates the child information (columns) about the current object (table)
        /// </summary>
        /// <returns></returns>
        public IEnumerable <SqlDbColumnInfo> EnumerateChildren()
        {
            using (var connect = Database.CreateConnection())
            {
                connect.Open();
                using (var da = new SqlDataAdapter($"select * from {TableName}", connect))
                {
                    var dt = new DataTable();
                    try
                    {
                        da.FillSchema(dt, SchemaType.Source);
                    }
                    catch { yield break; }

                    foreach (var col in dt.Columns.Cast <DataColumn>().OrderBy((c) => c.ColumnName))
                    {
                        SqlDbColumnInfo info = null;
                        try
                        {
                            info = new SqlDbColumnInfo
                            {
                                AllowNulls = col.AllowDBNull,
                                ColumnName = col.ColumnName,
                                DataType   = col.DataType.Name,
                                IsKey      = dt.PrimaryKey.Contains(col),
                                Ordinal    = col.Ordinal
                            };
                        }
                        catch (Exception cols_error)
                        {
                            System.Diagnostics.Debug.Print(cols_error.ToString());
                        }

                        if (info != null)
                        {
                            yield return(info);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// construct the view-model for the column
 /// </summary>
 /// <param name="info"></param>
 public SqlColumnViewModel(SqlDbColumnInfo info)
 {
     this.Name       = info.Description;
     this.Foreground = Brushes.Blue;
     this.Icon       = icon;
 }