protected override void FillForeignKeyColumns(DBSchemaForeignKey anFk, DataTable dtColumns) { DataColumn fktblcol = GetColumn(dtColumns, "FKTableName", true); DataColumn fkschcol = GetColumn(dtColumns, "FKTableSchema", true); DataColumn fkcatcol = GetColumn(dtColumns, "FKTableCatalog", true); DataColumn fkcolumn = GetColumn(dtColumns, "FKColumnName", true); DataColumn pktblcol = GetColumn(dtColumns, "PKTableName", true); DataColumn pkschcol = GetColumn(dtColumns, "PKTableSchema", true); DataColumn pkcatcol = GetColumn(dtColumns, "PKTableCatalog", true); DataColumn pkcolumn = GetColumn(dtColumns, "PKColumnName", true); bool first = true; foreach (DataRow row in dtColumns.Rows) { if (first) { first = false; //populate the references to the foreign key tables and primary key tables DBSchemaItemRef fktbl = new DBSchemaItemRef(DBSchemaTypes.Table, GetColumnStringValue(row, fkcatcol), GetColumnStringValue(row, fkschcol), GetColumnStringValue(row, fktblcol)); anFk.ForeignKeyTable = fktbl; DBSchemaItemRef pktbl = new DBSchemaItemRef(DBSchemaTypes.Table, GetColumnStringValue(row, pkcatcol), GetColumnStringValue(row, pkschcol), GetColumnStringValue(row, pktblcol)); anFk.PrimaryKeyTable = pktbl; } DBSchemaForeignKeyMapping map = new DBSchemaForeignKeyMapping(); map.ForeignColumn = GetColumnStringValue(row, fkcolumn); map.PrimaryColumn = GetColumnStringValue(row, pkcolumn); anFk.Mappings.Add(map); } }
/// <summary> /// populates the meta data for a specific foreign key /// </summary> /// <param name="fk"></param> /// <param name="dtFKRow"></param> protected override void FillForeignKeyData(DBSchemaForeignKey fk, DataRow dtFKRow) { DataTable dt = dtFKRow.Table; DataColumn schemacol = GetColumn(dt, "FK_SCHEMA", false); DataColumn catalogcol = GetColumn(dt, "FK_CATALOG", false); DataColumn namecol = GetColumn(dt, "FK_NAME", true); DataColumn pkcatalogcol = GetColumn(dt, "PK_CATALOG_NAME", false); DataColumn pkschemacol = GetColumn(dt, "PK_SCHEMA_NAME", false); DataColumn pktablecol = GetColumn(dt, "PK_TABLE_NAME", true); DataColumn pkcolumncol = GetColumn(dt, "PK_COLUMN_NAME", true); DataColumn fkcatalogcol = GetColumn(dt, "FK_CATALOG_NAME", false); DataColumn fkschemacol = GetColumn(dt, "FK_SCHEMA_NAME", false); DataColumn fktablecol = GetColumn(dt, "FK_TABLE_NAME", false); DataColumn fkcolumncol = GetColumn(dt, "FK_COLUMN_NAME", false); fk.Catalog = GetColumnStringValue(dtFKRow, catalogcol); fk.Schema = GetColumnStringValue(dtFKRow, schemacol); fk.Name = GetColumnStringValue(dtFKRow, namecol); DBSchemaItemRef pktable = new DBSchemaItemRef(DBSchemaTypes.Table, GetColumnStringValue(dtFKRow, pkcatalogcol), GetColumnStringValue(dtFKRow, pkschemacol), GetColumnStringValue(dtFKRow, pktablecol)); DBSchemaItemRef fktable = new DBSchemaItemRef(DBSchemaTypes.Table, GetColumnStringValue(dtFKRow, fkcatalogcol), GetColumnStringValue(dtFKRow, fkschemacol), GetColumnStringValue(dtFKRow, fktablecol)); fk.ForeignKeyTable = fktable; fk.PrimaryKeyTable = pktable; DBSchemaForeignKeyMapping map = new DBSchemaForeignKeyMapping(); map.ForeignColumn = GetColumnStringValue(dtFKRow, fkcolumncol); map.PrimaryColumn = GetColumnStringValue(dtFKRow, pkcolumncol); fk.Mappings.Add(map); }
protected void FillForeignKeyColumns(DBSchemaForeignKey anFk, DataTable fkColumns, DataTable pkColumns) { if (fkColumns.Rows.Count == pkColumns.Rows.Count) { DataColumn fkNameCol = fkColumns.Columns["COLUMN_NAME"]; DataColumn pkNameCol = pkColumns.Columns["COLUMN_NAME"]; for (int i = 0; i < fkColumns.Rows.Count; i++) { DBSchemaForeignKeyMapping mapping = new DBSchemaForeignKeyMapping(); mapping.PrimaryColumn = GetColumnStringValue(pkColumns.Rows[i], pkNameCol); mapping.ForeignColumn = GetColumnStringValue(fkColumns.Rows[i], fkNameCol); anFk.Mappings.Add(mapping); } } else { //Cannot do anything as we cannot match } }
protected override void FillForeignKeyData(DBSchemaForeignKey fk, DataRow dtFKRow) { DataTable tbl = dtFKRow.Table; DataColumn catalog = GetColumn(tbl, "CONSTRAINT_CATALOG", false); DataColumn schema = GetColumn(tbl, "CONSTRAINT_SCHEMA", false); DataColumn name = GetColumn(tbl, "CONSTRAINT_NAME", true); fk.Catalog = GetColumnStringValue(dtFKRow, catalog); fk.Schema = GetColumnStringValue(dtFKRow, schema); fk.Name = GetColumnStringValue(dtFKRow, name); DataColumn fkFromCatalog = GetColumn(tbl, "TABLE_CATALOG", false); DataColumn fkFromSchema = GetColumn(tbl, "TABLE_SCHEMA", false); DataColumn fkFromTable = GetColumn(tbl, "TABLE_NAME", false); DataColumn fkFromColumn = GetColumn(tbl, "FKEY_FROM_COLUMN", true); DataColumn fkToCatalog = GetColumn(tbl, "FKEY_TO_CATALOG", false); DataColumn fkToSchema = GetColumn(tbl, "FKEY_TO_SCHEMA", false); DataColumn fkToTable = GetColumn(tbl, "FKEY_TO_TABLE", true); DataColumn fkToColumn = GetColumn(tbl, "FKEY_TO_COLUMN", true); fk.ForeignKeyTable = new DBSchemaItemRef(DBSchemaTypes.Table, GetColumnStringValue(dtFKRow, fkFromCatalog), GetColumnStringValue(dtFKRow, fkFromSchema), GetColumnStringValue(dtFKRow, fkFromTable)); fk.PrimaryKeyTable = new DBSchemaItemRef(DBSchemaTypes.Table, GetColumnStringValue(dtFKRow, fkToCatalog), GetColumnStringValue(dtFKRow, fkToSchema), GetColumnStringValue(dtFKRow, fkToTable)); DBSchemaForeignKeyMapping map = new DBSchemaForeignKeyMapping(); map.ForeignColumn = GetColumnStringValue(dtFKRow, fkFromColumn); map.PrimaryColumn = GetColumnStringValue(dtFKRow, fkToColumn); fk.Mappings.Add(map); }