/// <summary>The get columns for table.</summary>
        /// <param name="dbTable">The db table.</param>
        /// <param name="schemaTableKeyInfo">The schema table key info.</param>
        /// <param name="dbTypes">The db types.</param>
        protected virtual void GetColumnsForTable(DbModelTable dbTable, DataTable schemaTableKeyInfo, Dictionary <string, DbModelType> dbTypes)
        {
            if (schemaTableKeyInfo == null)
            {
                return;
            }

            foreach (DataRow columnRow in schemaTableKeyInfo.Rows)
            {
                if (SafeGetBool(columnRow, "IsHidden"))
                {
                    continue;
                }

                string columnName = SafeGetString(columnRow, "ColumnName");
                string dataType   = GetDataTypeNameForColumn(dbTable, schemaTableKeyInfo, columnRow);

                // note - need a better work around for columns missing the data type info (e.g. access)
                if (string.IsNullOrEmpty(dataType))
                {
                    // try using the "ProviderDbType" to match
                    string providerDbType = SafeGetString(columnRow, "ProviderType");
                    foreach (var type in dbTypes.Values)
                    {
                        if (type.ProviderDbType == providerDbType)
                        {
                            dataType = type.Name;
                            break;
                        }
                    }
                }

                DbModelType dbType = DbModelType.Create(
                    dbTypes,
                    dataType,
                    SafeGetInt(columnRow, "ColumnSize"),
                    SafeGetInt(columnRow, "Precision"),
                    SafeGetInt(columnRow, "Scale"),
                    SafeGetString(columnRow, "DataType"));

                // todo - FK info
                DbModelColumn dbColumn = new DbModelColumn
                {
                    Name = columnName,
// Name = MakeSqlFriendly(columnName),
                    Nullable        = SafeGetBool(columnRow, "AllowDBNull"),
                    IsKey           = SafeGetBool(columnRow, "IsKey"),
                    IsUnique        = SafeGetBool(columnRow, "IsUnique"),
                    IsRowVersion    = SafeGetBool(columnRow, "IsRowVersion"),
                    IsIdentity      = SafeGetBool(columnRow, "IsIdentity"),
                    IsAutoIncrement = SafeGetBool(columnRow, "IsAutoIncrement"),
                    IsReadOnly      = SafeGetBool(columnRow, "IsReadOnly"),
                    DbType          = dbType,
                };
                dbTable.Add(dbColumn);
            }
        }
Пример #2
0
        /// <summary>The write create.</summary>
        /// <param name="writer">The writer.</param>
        /// <param name="column">The column.</param>
        public virtual void WriteCreate(TextWriter writer, DbModelColumn column)
        {
            writer.Write("{0} {1} ", MakeSqlFriendly(column.Name), column.DbType.Summary);

            if (!column.Nullable)
            {
                writer.Write("not ");
            }

            writer.Write("null");
        }
Пример #3
0
        /// <summary>The write create.</summary>
        /// <param name="writer">The writer.</param>
        /// <param name="column">The column.</param>
        public virtual void WriteCreate(TextWriter writer, DbModelColumn column)
        {
            writer.Write("{0} {1} ", MakeSqlFriendly(column.Name), column.DbType.Summary);

            if (!column.Nullable)
            {
                writer.Write("not ");
            }

            writer.Write("null");
        }
 /// <summary>Initializes a new instance of the <see cref="DbModelForeignKeyReference"/> class.</summary>
 /// <param name="owningColumn">The owning column.</param>
 /// <param name="fkTable">The fk table.</param>
 /// <param name="fkColumn">The fk column.</param>
 public DbModelForeignKeyReference(DbModelColumn owningColumn, DbModelTable fkTable, DbModelColumn fkColumn)
 {
     OwningColumn = owningColumn;
     ReferenceTable = fkTable;
     ReferenceColumn = fkColumn;
 }
 /// <summary>Adds the <paramref name="column"/> to the list of <see cref="Columns"/> assigning the <see cref="DbModelColumn.ParentTable"/>.</summary>
 /// <param name="column">The new column.</param>
 public virtual void Add(DbModelColumn column)
 {
     column.ParentTable = this;
     Columns.Add(column);
 }
Пример #6
0
 /// <summary>Adds the <paramref name="column"/> to the list of <see cref="Columns"/> assigning the <see cref="DbModelColumn.ParentTable"/>.</summary>
 /// <param name="column">The new column.</param>
 public virtual void Add(DbModelColumn column)
 {
     column.ParentTable = this;
     Columns.Add(column);
 }
        /// <summary>The get summary.</summary>
        /// <param name="column">The column.</param>
        /// <returns>The get summary.</returns>
        private string GetSummary(DbModelColumn column)
        {
            StringWriter stringWriter = new StringWriter();
            if (_sqlWriter == null)
            {
                _sqlWriter = _services.Resolve<ISqlWriter>();
            }

            _sqlWriter.WriteSummary(stringWriter, column);
            return stringWriter.ToString();
        }
        /// <summary>The build tool tip.</summary>
        /// <param name="table">The table.</param>
        /// <param name="column">The column.</param>
        /// <returns>The build tool tip.</returns>
        private string BuildToolTip(DbModelTable table, DbModelColumn column)
        {
            string friendlyColumnName = Utility.MakeSqlFriendly(column.Name);
            string toolTip = table.FullName + "." + friendlyColumnName;
            if (column.IsKey)
            {
                toolTip += "; Primary Key";
            }

            if (column.IsAutoIncrement)
            {
                toolTip += "; Auto*";
            }

            if (column.ForeignKeyReference != null)
            {
                toolTip += string.Format("; FK -> {0}.{1}", column.ForeignKeyReference.ReferenceTable.FullName, column.ForeignKeyReference.ReferenceColumn.Name);
            }

            if (column.IsReadOnly)
            {
                toolTip += "; Read Only";
            }

            return toolTip;
        }
        /// <summary>The build image key.</summary>
        /// <param name="column">The column.</param>
        /// <returns>The build image key.</returns>
        private string BuildImageKey(DbModelColumn column)
        {
            string imageKey = column.ObjectType;
            if (column.IsRowVersion)
            {
                imageKey += "-RowVersion";
            }
            else
            {
                if (column.IsKey)
                {
                    imageKey += "-PK";
                }

                if (column.ForeignKeyReference != null)
                {
                    imageKey += "-FK";
                }
            }

            return imageKey;
        }
        /// <summary>The get columns for table.</summary>
        /// <param name="dbTable">The db table.</param>
        /// <param name="schemaTableKeyInfo">The schema table key info.</param>
        /// <param name="dbTypes">The db types.</param>
        protected virtual void GetColumnsForTable(DbModelTable dbTable, DataTable schemaTableKeyInfo, Dictionary<string, DbModelType> dbTypes)
        {
            if (schemaTableKeyInfo == null)
            {
                return;
            }

            foreach (DataRow columnRow in schemaTableKeyInfo.Rows)
            {
                if (SafeGetBool(columnRow, "IsHidden"))
                {
                    continue;
                }

                string columnName = SafeGetString(columnRow, "ColumnName");
                string dataType = GetDataTypeNameForColumn(dbTable, schemaTableKeyInfo, columnRow);

                // note - need a better work around for columns missing the data type info (e.g. access)
                if (string.IsNullOrEmpty(dataType))
                {
                    // try using the "ProviderDbType" to match
                    string providerDbType = SafeGetString(columnRow, "ProviderType");
                    foreach (var type in dbTypes.Values)
                    {
                        if (type.ProviderDbType == providerDbType)
                        {
                            dataType = type.Name;
                            break;
                        }
                    }
                }

                DbModelType dbType = DbModelType.Create(
                    dbTypes,
                    dataType,
                    SafeGetInt(columnRow, "ColumnSize"),
                    SafeGetInt(columnRow, "Precision"),
                    SafeGetInt(columnRow, "Scale"),
                    SafeGetString(columnRow, "DataType"));

                // todo - FK info
                DbModelColumn dbColumn = new DbModelColumn
                                         	{
                                         		Name = columnName,
            // Name = MakeSqlFriendly(columnName),
                                         		Nullable = SafeGetBool(columnRow, "AllowDBNull"),
                                         		IsKey = SafeGetBool(columnRow, "IsKey"),
                                         		IsUnique = SafeGetBool(columnRow, "IsUnique"),
                                         		IsRowVersion = SafeGetBool(columnRow, "IsRowVersion"),
                                         		IsIdentity = SafeGetBool(columnRow, "IsIdentity"),
                                         		IsAutoIncrement = SafeGetBool(columnRow, "IsAutoIncrement"),
                                         		IsReadOnly = SafeGetBool(columnRow, "IsReadOnly"),
                                         		DbType = dbType,
                                         	};
                dbTable.Add(dbColumn);
            }
        }
 /// <summary>Initializes a new instance of the <see cref="DbModelForeignKeyReference"/> class.</summary>
 /// <param name="owningColumn">The owning column.</param>
 /// <param name="fkTable">The fk table.</param>
 /// <param name="fkColumn">The fk column.</param>
 public DbModelForeignKeyReference(DbModelColumn owningColumn, DbModelTable fkTable, DbModelColumn fkColumn)
 {
     OwningColumn    = owningColumn;
     ReferenceTable  = fkTable;
     ReferenceColumn = fkColumn;
 }