本文整理汇总了C#中Key.ResetDefaults方法的典型用法代码示例。如果您正苦于以下问题:C# Key.ResetDefaults方法的具体用法?C# Key.ResetDefaults怎么用?C# Key.ResetDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Key
的用法示例。
在下文中一共展示了Key.ResetDefaults方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNewTable
//.........这里部分代码省略.........
else if (indexKeyType == "CHECK")
{
indexType = DatabaseConstant.IndexType.Check;
}
else if (indexKeyType == "NONE") //TODO check is NONE
{
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
示例2: GetKeys
private void GetKeys(ITable table)
{
DataRow[] keyRows = connector.Indexes.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}'", table.Name.Replace("'", "''"), table.Schema));
for (int i = 0; i < keyRows.Length; i++)
{
DataRow keyRow = keyRows[i];
DatabaseKeyType keyType;
string indexKeyType = keyRow["CONSTRAINT_TYPE"].ToString();
if (indexKeyType == "PRIMARY KEY")
{
keyType = DatabaseKeyType.Primary;
}
else if (indexKeyType == "UNIQUE")
{
keyType = DatabaseKeyType.Unique;
}
else
{
continue;
}
Key key = new Key
{
Name = keyRow["INDEX_NAME"].ToString(),
IsUserDefined = false,
Keytype = keyType,
Parent = table,
IsUnique = true
};
// Fill Columns
List<DataRow> keyColumnRows = new List<DataRow>();
keyColumnRows.AddRange(connector.Columns.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}' AND COLUMN_NAME = '{2}'", table.Name.Replace("'", "''"), table.Schema, keyRow["COLUMN_NAME"])));
while ((i < keyRows.Length - 1) && (string)keyRows[i + 1]["TABLE_NAME"] == table.Name && (string)keyRows[i + 1]["INDEX_NAME"] == (string)keyRow["INDEX_NAME"])
{
i++;
keyRow = keyRows[i];
keyColumnRows.AddRange(connector.Columns.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}' AND COLUMN_NAME = '{2}'", table.Name.Replace("'", "''"), table.Schema, keyRow["COLUMN_NAME"])));
}
// Fill Columns
foreach (DataRow keyColumnRow in keyColumnRows)
{
key.AddColumn((string)keyColumnRow["COLUMN_NAME"]);
}
key.ResetDefaults();
table.AddKey(key);
}
}
示例3: GetKeys
private void GetKeys(ITable table)
{
List<DataRow> keyRows = connector.GetIndexRows(table.Schema, table.Name.Replace("'", "''"));
for (int i = 0; i < keyRows.Count; i++)
{
DataRow keyRow = keyRows[i];
DatabaseKeyType keyType;
string indexKeyType = keyRow["CONSTRAINT_TYPE"].ToString();
/*if (indexKeyType == "PRIMARY KEY")
keyType = DatabaseKeyType.Primary;
else*/
if (indexKeyType == "UNIQUE")
keyType = DatabaseKeyType.Unique;
else
continue;
Key key = new Key
{
Name = keyRow["INDEX_NAME"].ToString(),
IsUserDefined = false,
Keytype = keyType,
Parent = table,
IsUnique = true
};
// Fill Columns
List<DataRow> keyColumnRows = new List<DataRow>();
keyColumnRows.AddRange(connector.ColumnsBySchema[table.Schema][table.Name.Replace("'", "''")].Where(r => r[OrdColumn].ToString() == keyRow["COLUMN_NAME"].ToString()));
while ((i < keyRows.Count - 1) && (string)keyRows[i + 1]["TABLE_NAME"] == table.Name && (string)keyRows[i + 1]["INDEX_NAME"] == (string)keyRow["INDEX_NAME"])
{
i++;
keyRow = keyRows[i];
keyColumnRows.AddRange(connector.ColumnsBySchema[table.Schema][table.Name.Replace("'", "''")].Where(c => c[OrdColumn].ToString() == keyRow["COLUMN_NAME"].ToString()));
}
// Fill Columns
foreach (DataRow keyColumnRow in keyColumnRows)
key.AddColumn((string)keyColumnRow["COLUMN_NAME"]);
key.ResetDefaults();
table.AddKey(key);
}
// Add Primary Keys
var primaryKeyNames = connector.PrimaryKeyNames;
if (primaryKeyNames.ContainsKey(table.Schema) && primaryKeyNames[table.Schema].ContainsKey(table.Name))
{
Key key = new Key
{
Name = primaryKeyNames[table.Schema][table.Name],
IsUserDefined = false,
Keytype = DatabaseKeyType.Primary,
Parent = table,
IsUnique = true
};
// Fill Columns
foreach (var column in table.ColumnsInPrimaryKey)
key.AddColumn(column.Name);
key.ResetDefaults();
table.AddKey(key);
}
}