本文整理汇总了C#中Key.AddReferencedColumn方法的典型用法代码示例。如果您正苦于以下问题:C# Key.AddReferencedColumn方法的具体用法?C# Key.AddReferencedColumn怎么用?C# Key.AddReferencedColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Key
的用法示例。
在下文中一共展示了Key.AddReferencedColumn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNewTable
//.........这里部分代码省略.........
indexType = DatabaseConstant.IndexType.None;
}
else
{
//continue;
throw new Exception("IndexType " + indexKeyType + " Not Defined");
}
List<DataRow> indexColumnRows = new List<DataRow>();// = IndexColumns.Select(string.Format("TABLE_NAME = '{0}' AND CONSTRAINT_NAME = '{1}'", tableName, indexRow["CONSTRAINT_NAME"]));
indexColumnRows.AddRange(Columns.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME = '{2}'", schema, tableName, indexRow["COLUMN_NAME"])));
while ((i < indexRows.Length - 1) && (string)indexRows[i + 1]["TABLE_NAME"] == tableName && (string)indexRows[i + 1]["CONSTRAINT_NAME"] == (string)indexRow["CONSTRAINT_NAME"])
{
i++;
indexRow = indexRows[i];
indexColumnRows.AddRange(Columns.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME = '{2}'", schema, tableName, indexRow["COLUMN_NAME"])));
}
bool isUnique = (int)indexRow["IS_UNIQUE"] == 1 ? true : false;
bool isClustered = (int)indexRow["IS_CLUSTERED"] == 1 ? true : false;
Index index = new Index(indexRow["CONSTRAINT_NAME"].ToString(), false, indexType, table, isUnique, isClustered);
// Fill Columns
foreach (DataRow indexColumnRow in indexColumnRows)
{
Column indexColumn = new Column(indexColumnRow["COLUMN_NAME"].ToString(), false);
index.AddColumn(indexColumn);
}
index.ResetDefaults();
table.AddIndex(index);
}
// Indexes -- that should be keys
DataRow[] keyRows = Indexes.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}'", schema, tableName));
//foreach (DataRow keyRow in indexRows)
for (int i = 0; i < keyRows.Length; i++)
{
DataRow keyRow = keyRows[i];
string keyType;
string indexKeyType = keyRow["CONSTRAINT_TYPE"].ToString();
if (indexKeyType == "PRIMARY KEY")
{
keyType = DatabaseConstant.KeyType.Primary;
}
else if (indexKeyType == "FOREIGN KEY")
{
keyType = DatabaseConstant.KeyType.Foreign;
}
else if (indexKeyType == "UNIQUE")
{
keyType = DatabaseConstant.KeyType.Unique;
}
else
{
continue;
}
Key key = new Key(keyRow["CONSTRAINT_NAME"].ToString(), false, keyType, table, false);
// Fill Columns
List<DataRow> keyColumnRows = new List<DataRow>();
keyColumnRows.AddRange(Columns.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME = '{2}'", schema, tableName, keyRow["COLUMN_NAME"])));
while ((i < keyRows.Length - 1) && (string)keyRows[i + 1]["TABLE_NAME"] == tableName && (string)keyRows[i + 1]["CONSTRAINT_NAME"] == (string)keyRow["CONSTRAINT_NAME"])
{
i++;
keyRow = keyRows[i];
keyColumnRows.AddRange(Columns.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME = '{2}'", schema, tableName, keyRow["COLUMN_NAME"])));
}
// Fill Columns
foreach (DataRow keyColumnRow in keyColumnRows)
{
Column keyColumn = new Column(keyColumnRow["COLUMN_NAME"].ToString(), false);
keyColumn.DataType = (string)keyColumnRow["DATA_TYPE"];
key.AddColumn(keyColumn);
}
if (keyType == DatabaseConstant.KeyType.Foreign)
{
DataRow[] keyReferencedColumnRows = IndexReferencedColumns.Select(string.Format("ForeignKeySchema = '{0}' AND ForeignKeyTable = '{1}' AND ForeignKey = '{2}'", schema, tableName, keyRow["CONSTRAINT_NAME"]));
DataRow firstKeyReferencedColumnRow = keyReferencedColumnRows[0];
// Fill References
key.ReferencedTable = new Model.Table(firstKeyReferencedColumnRow["ReferencedTable"].ToString(), false) { Schema = firstKeyReferencedColumnRow["ReferencedSchema"].ToString() };
key.ReferencedKey = new Key(firstKeyReferencedColumnRow["ReferencedKey"].ToString(), false, true);
// Fill Referenced Columns
foreach (DataRow keyReferencedColumnRow in keyReferencedColumnRows)
{
Column keyReferencedColumn = new Column(keyReferencedColumnRow["ReferencedColumn"].ToString(), false);
key.AddReferencedColumn(keyReferencedColumn);
}
}
key.ResetDefaults();
table.AddKey(key);
}
#endregion
return table;
}