public void ShouldAddRangeOfColumns() { TableEntity table = new TableEntity("dbo", "Customer"); var idColumn = DatabaseEntityFactory.CreateColumnEntity( "CustomerId", new ColumnDataTypeDefinition("int", true), true, 1, false, string.Empty, null); var nameColumn = DatabaseEntityFactory.CreateColumnEntity( "CustomerName", new ColumnDataTypeDefinition("varchar(500)", true), false, 2, false, string.Empty, null); IEnumerable <ColumnEntity> columnsToAdd = new List <ColumnEntity> { idColumn, nameColumn }; table.AddColumns(columnsToAdd); Assert.That(table.Columns.Contains(idColumn)); Assert.That(table.Columns.Contains(nameColumn)); Assert.That(table.HasIdentityColumn); }
/// <summary> /// Create a TableEntity and get all its columns /// </summary> /// <param name="tableSchema">schema name of the table to get</param> /// <param name="tableName">tableName of the table to get</param> /// <returns></returns> public TableEntity GetTableAndColumns(string tableSchema, string tableName) { using (ColumnEntityDataAccess colDa = new ColumnEntityDataAccess(this._connectionString)) { TableEntity table = GetOne(string.Format("select Table_Name, Table_Schema from information_Schema.Tables WITH(NOLOCK) where table_schema = '{0}' and table_name = '{1}'", tableSchema, tableName), CreateTableEntity); table.AddColumns(colDa.GetAllColumnsForTable(table)); // // TODO: Dont add these foreign key generators here. Should be handled more central foreach (var column in table.Columns.Where(x => x.IsForeignKey)) { GetForeignKeyGeneratorsForColumn(column); } table.RefreshWarnings(); return(table); } }