本文整理汇总了C#中TableSchema.IsKeyExist方法的典型用法代码示例。如果您正苦于以下问题:C# TableSchema.IsKeyExist方法的具体用法?C# TableSchema.IsKeyExist怎么用?C# TableSchema.IsKeyExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableSchema
的用法示例。
在下文中一共展示了TableSchema.IsKeyExist方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIndexes
private static List<IndexSchema> GetIndexes(DbConnection con, TableSchema eTable)
{
var aStore = new List<IndexSchema>();
string[] restrict3 = {null, null, eTable.Name};
string[] restrict4 = {null, null, eTable.Name, null};
// INDEX_TYPE = 0 - ascending, 1 - descending
restrict4[0] = null;
restrict4[1] = null;
restrict4[2] = eTable.Name;
restrict4[3] = null;
var dtShema = con.GetSchema("Indexes", restrict3);
aStore.Clear();
for (var x = 0; x < dtShema.Rows.Count; x++)
{
var cRow = dtShema.Rows[x];
var cName = cRow["INDEX_NAME"].ToString();
if (eTable.IsKeyExist(cName, ConstraintType.Unique) ||
eTable.IsKeyExist(cName, ConstraintType.KeyPrimary) ||
eTable.IsKeyExist(cName, ConstraintType.KeyForeign))
continue;
var eIndex = new IndexSchema();
var columns = "";
eIndex.Name = cName;
eIndex.Unique = Convert.ToBoolean(cRow["IS_UNIQUE"], CultureInfo.InvariantCulture);
if (cRow["INDEX_TYPE"] == DBNull.Value)
eIndex.Sort = SortOrder.Ascending;
else
eIndex.Sort = Convert.ToInt32(cRow["INDEX_TYPE"], CultureInfo.InvariantCulture) == 0
? SortOrder.Ascending
: SortOrder.Descending;
eIndex.IsActive = !Convert.ToBoolean(cRow["IS_INACTIVE"], CultureInfo.InvariantCulture);
restrict4[3] = cName;
var dtShemaCols = con.GetSchema("IndexColumns", restrict4);
var dtv = dtShemaCols.DefaultView;
//dtv.RowFilter = "INDEX_NAME = '" + cName + "'";
dtv.Sort = "ORDINAL_POSITION ASC";
for (var y = 0; y < dtv.Count; y++)
columns += (dtv[y]["COLUMN_NAME"] + ", ");
columns = columns.Remove(columns.Length - 2, 2);
eIndex.Columns = columns;
aStore.Add(eIndex);
}
return aStore;
}
示例2: GetIndexes
private static List<IndexSchema> GetIndexes(DbConnection con, TableSchema eTable)
{
var aStore = new List<IndexSchema>();
var aHash = new List<string>();
string[] restrict4 = {null, null, null, null};
string[] restrict5 = {null, null, null, null, null};
// INDEX_TYPE = 0 - ascending, 1 - descending
restrict4[2] = eTable.Name;
restrict5[2] = eTable.Name;
var dtShema = con.GetSchema("Indexes", restrict4);
aStore.Clear();
aHash.Clear();
for (var x = 0; x < dtShema.Rows.Count; x++)
{
var cRow = dtShema.Rows[x];
var cName = cRow["INDEX_NAME"].ToString();
if (eTable.IsKeyExist(cName, ConstraintType.Unique) ||
eTable.IsKeyExist(cName, ConstraintType.KeyPrimary) ||
eTable.IsKeyExist(cName, ConstraintType.KeyForeign) ||
Convert.ToBoolean(cRow["PRIMARY_KEY"], CultureInfo.InvariantCulture))
continue;
if (aHash.Contains(cName))
continue;
var eIndex = new IndexSchema();
var columns = String.Empty;
aHash.Add(cName);
eIndex.Name = cName;
eIndex.Unique = Convert.ToBoolean(cRow["UNIQUE"], CultureInfo.InvariantCulture);
if (cRow["TYPE"] == DBNull.Value)
eIndex.Sort = SortOrder.Ascending;
else
eIndex.Sort = Convert.ToInt32(cRow["TYPE"], CultureInfo.InvariantCulture) == 0
? SortOrder.Ascending
: SortOrder.Descending;
eIndex.IsActive = true;
// !Convert.ToBoolean(cRow["IS_INACTIVE"], CultureInfo.InvariantCulture);
restrict5[3] = cName;
var dtIndexColumns = con.GetSchema("IndexColumns", restrict5);
var first = true;
for (var y = 0; y < dtIndexColumns.Rows.Count; y++)
{
if (first)
first = false;
else
columns += ", ";
columns += dtIndexColumns.Rows[y]["COLUMN_NAME"];
}
eIndex.Columns = columns;
aStore.Add(eIndex);
}
return aStore;
}
示例3: GetIndexes
private static List<IndexSchema> GetIndexes(SqlConnection con, TableSchema eTable)
{
var indexes = new List<IndexSchema>();
var aHash = new Dictionary<string, bool>();
string[] restrict4 = {null, null, null, null};
// Indexes
restrict4[0] = null;
restrict4[1] = null;
restrict4[2] = eTable.Name;
restrict4[3] = null;
var dtShema = SqlSchemaFactory.GetSchema(con, "Indexes", restrict4);
for (var i = 0; i < dtShema.Rows.Count; i++)
{
var row = dtShema.Rows[i];
if (Convert.ToBoolean(row["IS_STATISTICS"], CultureInfo.InvariantCulture) ||
Convert.ToBoolean(row["IS_AUTOSTATISTICS"], CultureInfo.InvariantCulture) ||
Convert.ToBoolean(row["IS_HYPOTTETICAL"], CultureInfo.InvariantCulture))
continue;
var cName = row["INDEX_NAME"].ToString();
if (eTable.IsKeyExist(cName, ConstraintType.Unique) ||
eTable.IsKeyExist(cName, ConstraintType.KeyPrimary) ||
eTable.IsKeyExist(cName, ConstraintType.KeyForeign))
continue;
if (aHash.ContainsKey(cName))
continue;
var eIndex = new IndexSchema();
aHash.Add(cName, true);
eIndex.Name = cName;
eIndex.Unique = Convert.ToBoolean(row["IS_UNIQUE"], CultureInfo.InvariantCulture);
eIndex.Clustered = Convert.ToBoolean(row["IS_CLUSTERED"], CultureInfo.InvariantCulture);
//eIndex.isActive = !Convert.ToBoolean(cRow["IS_INACTIVE"], CultureInfo.InvariantCulture);
var dtv = dtShema.DefaultView;
dtv.RowFilter = string.Format("INDEX_NAME = '{0}'", cName);
dtv.Sort = "COLUMN_ORDINAL_POSITION ASC";
var columns = "";
for (var y = 0; y < dtv.Count; y++)
columns += (dtv[y]["COLUMN_NAME"] +
(Convert.ToBoolean(dtv[y]["IS_DESCENDING"], CultureInfo.InvariantCulture) ? " DESC" : "") +
", ");
columns = columns.Remove(columns.Length - 2, 2);
eIndex.Columns = columns;
indexes.Add(eIndex);
}
return indexes;
}
示例4: LoadSchema
public static DBSchema LoadSchema(string connStr)
{
var dbsc = new DBSchema();
var catalog = (Catalog)new CatalogClass();
var conn = new ConnectionClass();
try
{
var csb = new JetConnectionStringBuilder(connStr);
var keysList = new List<KeySchema>();
var indexesList = new List<IndexSchema>();
conn.Open(csb.ConnectionString, string.Empty, string.Empty, 0);
catalog.ActiveConnection = conn;
var slashPos = csb.DataSource.LastIndexOf(@"\");
dbsc.Name = csb.DataSource.Substring(slashPos == -1 ? 0 : slashPos + 1);
foreach (var xTable in GetTables(catalog))
{
keysList.Clear();
indexesList.Clear();
var eTable = new TableSchema
{
Name = xTable.Name,
Columns = GetColumns(xTable).ToArray(),
Keys = GetKeys(xTable).ToArray(),
Indexes = GetIndexes(xTable).ToArray()
};
// Фильтрация ключей
foreach (var key in eTable.Keys)
{
// Долбаный Аксес создает при создании внешних ключей уникальные индексы.
if (key.KeyType == ConstraintType.KeyForeign && !eTable.IsIndexExist(key.Name))
continue;
if (key.KeyType == ConstraintType.Unique &&
eTable.IsKeyExist(key.Name, ConstraintType.KeyForeign))
continue;
keysList.Add(key);
}
eTable.Keys = keysList.ToArray();
// Фильтрация индексов
foreach (var index in eTable.Indexes)
{
if (eTable.IsKeyExist(index.Name, ConstraintType.Unique) ||
eTable.IsKeyExist(index.Name, ConstraintType.KeyPrimary) ||
eTable.IsKeyExist(index.Name, ConstraintType.KeyForeign))
continue;
indexesList.Add(index);
}
eTable.Indexes = indexesList.ToArray();
dbsc.Tables.Add(eTable);
}
}
finally
{
Marshal.ReleaseComObject(conn);
Marshal.ReleaseComObject(catalog);
}
return dbsc;
}