本文整理汇总了C#中Table.AddIndex方法的典型用法代码示例。如果您正苦于以下问题:C# Table.AddIndex方法的具体用法?C# Table.AddIndex怎么用?C# Table.AddIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.AddIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Both_Should_Not_Validate
public void Both_Should_Not_Validate()
{
var index1 = new Index { Name = "Index"};
var index2 = new Index { Name = "Index"};
var table = new Table("Table1");
table.AddIndex(index1);
table.AddIndex(index2);
ValidateIndex(index1);
ValidateIndex(index2);
}
示例2: It_Should_Validate_Correcty
public void It_Should_Validate_Correcty()
{
var index = new Index { Name = "Index1"};
var table = new Table("Table1");
table.AddIndex(index);
table.AddIndex(new Index { Name = "Index2"});
var failures = new List<ValidationFailure>();
Assert.That(index.ValidateObject(failures), Is.True);
Assert.That(failures, Is.Empty);
}
示例3: Should_Return_This
public void Should_Return_This()
{
const string expectedXML = @"<Table>" + When_Serialising_An_Empty_Table.ScriptBaseXml +
@"<Indexes>" + When_Serialising_An_Empty_Index.BasicIndexXml + @"</Indexes>" +
@"</Table>";
Table table = new Table("Entity1");
table.AddIndex(new Index("Index1"));
string outputXML = table.Serialise(new DatabaseSerialisationScheme());
outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML);
Assert.That(outputXML, Is.EqualTo(expectedXML));
}
示例4: TestDatabase
public static Database TestDatabase()
{
Database db = new Database("Test Database");
var t1 = new Table("Table1");
db.AddTable(t1);
t1.AddColumn(new Column("Column1") { InPrimaryKey = true, Datatype = "int", OrdinalPosition = 0, Size = 4});
t1.AddColumn(new Column("Column2") { Datatype = "nvarchar", OrdinalPosition = 1, Size = 100 });
t1.AddColumn(new Column("Column3") { Datatype = "datetime", OrdinalPosition = 2, Size = 8 });
t1.AddIndex(new Index("PK_Table1") { IsUnique = true, Datatype = DatabaseIndexType.PrimaryKey}).AddColumn("Column1");
t1.AddKey(new Key("PK_Table1", DatabaseKeyType.Primary)).AddColumn("Column1").AddColumn("Column2");
return db;
}
示例5: The_Original_Database_Should_Contain_A_Copy_Of_The_New_Table
public void The_Original_Database_Should_Contain_A_Copy_Of_The_New_Table()
{
var db1 = TestDatabaseLoader.TestDatabase();
Table newTable = new Table("Table2");
Column newColumn = new Column("Column1");
Key newKey = new Key("PrimaryKey");
Index newIndex = new Index("Index1");
newTable.AddColumn(newColumn);
newTable.AddKey(newKey);
newTable.AddIndex(newIndex);
TableAdditionOperation op = new TableAdditionOperation(db1, newTable);
op.RunOperation();
Assert.That(db1.Tables, Has.Count(2));
Assert.That(db1.Tables[1].Name, Is.EqualTo(newTable.Name));
Assert.That(db1.Tables[1], Is.Not.SameAs(newTable), "The added table should be a copy, not the original object.");
Assert.That(db1.Tables[1].Columns[0], Is.EqualTo(newColumn));
Assert.That(db1.Tables[1].Keys[0], Is.EqualTo(newKey));
Assert.That(db1.Tables[1].Indexes[0], Is.EqualTo(newIndex));
}
示例6: GetUniqueIndexes
private void GetUniqueIndexes(Table table)
{
DataRow[] indexRows = connector.GetUniqueIndexes().Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}'", table.Name.Replace("'", "''"), table.Schema));
for (int i = 0; i < indexRows.Length; i++)
{
DataRow indexRow = indexRows[i];
Index index = new Index
{
Name = (string)indexRow["INDEX_NAME"],
IsUserDefined = false,
IsUnique = true,
IsClustered = (long)indexRow["IS_CLUSTERED"] == 1,
IndexType = DatabaseIndexType.Unique,
Parent = table
};
List<DataRow> indexColumnRows = new List<DataRow>();
indexColumnRows.AddRange(connector.Columns.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}' AND COLUMN_NAME = '{2}'", table.Name.Replace("'", "''"), table.Schema, indexRow["COLUMN_NAME"])));
while ((i < indexRows.Length - 1) && (string)indexRows[i + 1]["TABLE_NAME"] == table.Name && (string)indexRows[i + 1]["INDEX_NAME"] == (string)indexRow["INDEX_NAME"])
{
i++;
indexRow = indexRows[i];
indexColumnRows.AddRange(connector.Columns.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}' AND COLUMN_NAME = '{2}'", table.Name.Replace("'", "''"), table.Schema, indexRow["COLUMN_NAME"])));
}
// Fill Columns
foreach (DataRow indexColumnRow in indexColumnRows)
{
var column = index.AddColumn((string)indexColumnRow["COLUMN_NAME"]);
if (index.IsUnique && indexColumnRows.Count == 1)
{
// Columns are only unique if the index has one column
column.IsUnique = true;
}
}
index.ResetDefaults();
table.AddIndex(index);
}
}
示例7: GetTableConstraintIndexes
internal void GetTableConstraintIndexes(Table table)
{
DataRow[] indexRows = connector.Indexes.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}'", table.Name.Replace("'", "''"), table.Schema));
for (int i = 0; i < indexRows.Length; i++)
{
DataRow indexRow = indexRows[i];
DatabaseIndexType indexType = GetIndexType(indexRow["CONSTRAINT_TYPE"].ToString());
var indexColumnRows = new List<DataRow>();
indexColumnRows.AddRange(connector.Columns.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}' AND COLUMN_NAME = '{2}'", table.Name.Replace("'", "''"), table.Schema, indexRow["COLUMN_NAME"])));
while ((i < indexRows.Length - 1) && (string)indexRows[i + 1]["TABLE_NAME"] == table.Name && (string)indexRows[i + 1]["INDEX_NAME"] == (string)indexRow["INDEX_NAME"])
{
i++;
indexRow = indexRows[i];
indexColumnRows.AddRange(connector.Columns.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}' AND COLUMN_NAME = '{2}'", table.Name.Replace("'", "''"), table.Schema, indexRow["COLUMN_NAME"])));
}
bool isUnique = (int)indexRow["IS_UNIQUE"] == 1;
bool isClustered = Convert.ToInt32(indexRow["IS_CLUSTERED"]) == 1;
Index index = new Index
{
Name = indexRow["INDEX_NAME"].ToString(),
IsUserDefined = false,
IndexType = indexType,
Parent = table,
IsUnique = isUnique,
IsClustered = isClustered
};
// Fill Columns
foreach (DataRow indexColumnRow in indexColumnRows)
{
var column = index.AddColumn((string)indexColumnRow["COLUMN_NAME"]);
if (index.IsUnique && indexColumnRows.Count == 1)
{
// Columns are only unique if the index has one column
column.IsUnique = true;
}
}
index.ResetDefaults();
table.AddIndex(index);
}
}
示例8: GetUniqueIndexes
private void GetUniqueIndexes(Table table)
{
List<DataRow> indexRows = connector.GetIndexRows(table.Schema, table.Name.Replace("'", "''"));
for (int i = 0; i < indexRows.Count; i++)
{
DataRow indexRow = indexRows[i];
Index index = new Index
{
Name = (string)indexRow["INDEX_NAME"],
IsUserDefined = false,
IsUnique = true,
IsClustered = Convert.ToInt32(indexRow["IS_CLUSTERED"]) == 1,
IndexType = DatabaseIndexType.Unique,
Parent = table
};
List<DataRow> indexColumnRows = new List<DataRow>();
indexColumnRows.AddRange(connector.ColumnsBySchema[table.Schema][table.Name.Replace("'", "''")].Where(c => c[OrdColumn].ToString() == indexRow["COLUMN_NAME"].ToString()));
while ((i < indexRows.Count - 1) && (string)indexRows[i + 1]["TABLE_NAME"] == table.Name && (string)indexRows[i + 1]["INDEX_NAME"] == (string)indexRow["INDEX_NAME"])
{
i++;
indexRow = indexRows[i];
indexColumnRows.AddRange(connector.ColumnsBySchema[table.Schema][table.Name.Replace("'", "''")].Where(c => c[OrdColumn].ToString() == indexRow["COLUMN_NAME"]));
}
// Fill Columns
foreach (DataRow indexColumnRow in indexColumnRows)
{
var column = index.AddColumn((string)indexColumnRow["COLUMN_NAME"]);
if (index.IsUnique && indexColumnRows.Count == 1)
{
// Columns are only unique if the index has one column
column.IsUnique = true;
}
}
index.ResetDefaults();
table.AddIndex(index);
}
}
示例9: It_Returns_The_IIndex_Objects
public void It_Returns_The_IIndex_Objects()
{
ProviderInfo info = new ProviderInfo();
var table1 = new Table();
var index1 = new Index("1");
table1.AddIndex(index1);
var table2 = new Table();
var index2 = new Index("2");
table2.AddIndex(index2);
info.MappingSet.Database.AddTable(table1);
info.MappingSet.Database.AddTable(table2);
IEnumerable<IScriptBaseObject> objects = info.GetAllObjectsOfType(typeof(IIndex));
Assert.That(objects, Has.Length(2));
Assert.That(objects.Contains(index1));
Assert.That(objects.Contains(index2));
}
示例10: Setup
public void Setup()
{
db = TestDatabaseLoader.TestDatabase();
var t2 = new Table("Table2");
db.AddTable(t2);
t2.AddColumn(new Column("Column1") { InPrimaryKey = true, Datatype = "int", OrdinalPosition = 0, Size = 4 });
t2.AddColumn(new Column("Column2") { Datatype = "nvarchar", OrdinalPosition = 1, Size = 100 });
t2.AddColumn(new Column("Column3") { Datatype = "datetime", OrdinalPosition = 2, Size = 8 });
t2.AddIndex(new Index("PK_Table2") { IsUnique = true, Datatype = DatabaseIndexType.PrimaryKey }).AddColumn("Column1");
t2.AddKey(new Key("PK_Table2") { Keytype = DatabaseKeyType.Primary }).AddColumn("Column1").AddColumn("Column2");
t2.CreateRelationshipTo(db.Tables[0]);
}