本文整理汇总了C#中Index.AddColumn方法的典型用法代码示例。如果您正苦于以下问题:C# Index.AddColumn方法的具体用法?C# Index.AddColumn怎么用?C# Index.AddColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Index
的用法示例。
在下文中一共展示了Index.AddColumn方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateIndexWithSameColumnTwoTimes_GetCorrectException
public void CreateIndexWithSameColumnTwoTimes_GetCorrectException()
{
// Arrange
var index = new Index("MyIndexName", "MyTable");
// Act
index.AddColumn("MyColumn");
// Assert
var ex = Assert.Throws<ArgumentException>(() => index.AddColumn("MyColumn"));
Assert.Equal("The column MyColumn is already added to index MyIndexName on table MyTable", ex.Message);
}
示例2: CreateIndexWithTwoColumns_GetValidCreateScript
public void CreateIndexWithTwoColumns_GetValidCreateScript()
{
// Arrange
var index = new Index("MyIndexName", "MyTable");
// Act
index.AddColumn("MyColumn");
index.AddColumn("MyOtherColumn");
// Assert
Assert.Equal(1, index.GetUpScript().Count);
Assert.Equal(2, index.Columns.Count);
Assert.Equal("CREATE INDEX MyIndexName \r\nON MyTable(MyColumn, MyOtherColumn)\r\n", index.GetUpScript().First());
}
示例3: CreateIndexWithOneColumn_GetValidCreateScript
public void CreateIndexWithOneColumn_GetValidCreateScript()
{
// Arrange
var index = new Index<MyTable>("MyIndexName", "MyTable");
// Act
index.AddColumn(m => m.MyColumn);
// Assert
Assert.Equal(1, index.GetUpScript().Count);
Assert.Equal("CREATE INDEX MyIndexName \r\nON MyTable(MyColumn)\r\n", index.GetUpScript().First());
}
示例4: CreateIndexWithOneColumn_GetOneColumnAdded
public void CreateIndexWithOneColumn_GetOneColumnAdded()
{
// Arrange
var index = new Index<MyTable>("MyIndexName", "MyTable");
// Act
index.AddColumn(m => m.MyColumn);
// Assert
Assert.Equal("MyIndexName", index.Name);
Assert.Equal("MyTable", index.TableName);
Assert.Equal(1, index.Columns.Count);
Assert.Equal("MyColumn", index.Columns.First());
}
示例5: 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);
}
}
示例6: 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);
}
}
示例7: Should_Return_This
public void Should_Return_This()
{
const string expectedXML = IndexWithColumnsXml;
Table table1 = new Table("Table1");
table1.AddColumn(new Column("Column1"));
Index index = new Index("Index1");
index.Parent = table1;
index.AddColumn("Column1");
string outputXML = index.Serialise(new DatabaseSerialisationScheme());
outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML);
Assert.That(outputXML, Is.EqualTo(expectedXML));
}
示例8: ProcessIndexNode
public IIndex ProcessIndexNode(XmlNode node, ITable parent, IDatabase db)
{
IIndex index = new Index();
index.Parent = parent;
ProcessScriptBase(index, node);
/*
<IsUnique>True</IsUnique>
<IsClustered>False</IsClustered>
<Datatype>Unique</Datatype>
<Columns>
<ColumnName>ColumnT13</ColumnName>
</Columns>
*/
NodeProcessor proc = new NodeProcessor(node);
index.IsUnique = proc.GetBool("IsUnique");
index.IsClustered = proc.GetBool("IsClustered");
index.IndexType = proc.GetEnum<DatabaseIndexType>("Datatype");
var columnNodeList = node.SelectNodes("Columns/ColumnName");
if (columnNodeList != null)
foreach (XmlNode columnRef in columnNodeList)
index.AddColumn(columnRef.InnerText);
return index;
}
示例9: 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);
}
}
示例10: The_Original_Index_Should_Be_Modified
public void The_Original_Index_Should_Be_Modified()
{
var db1 = TestDatabaseLoader.TestDatabase();
IIndex originalIndex = db1.Tables[0].Indexes[0];
originalIndex.Description = "old description";
IIndex newIndex = new Index(originalIndex.Name);
newIndex.Parent = new Table("Table1");
newIndex.Parent.AddColumn(new Column("Column2"));
newIndex.Description = "new description";
newIndex.AddColumn("Column2");
IndexChangeOperation op = new IndexChangeOperation(db1.Tables[0].Indexes[0], newIndex);
op.RunOperation();
op.RunSecondStep();
IIndex index = db1.Tables[0].Indexes[0];
Assert.That(db1.Tables[0].Indexes, Has.Count(1), "No new indexes should have been added");
Assert.That(index, Is.SameAs(originalIndex), "Index object should still be the same");
Assert.That(index.Description, Is.EqualTo("old description"));
Assert.That(index.Columns, Has.Count(1));
Assert.That(index.Columns[0].Name, Is.EqualTo("Column2"));
Assert.That(index.Columns[0], Is.Not.SameAs(newIndex.Columns[0]));
Assert.That(index.Columns[0], Is.SameAs(db1.Tables[0].Columns[1]), "The new Index should reference existing columns");
Assert.That(index.Parent, Is.SameAs(db1.Tables[0]), "The new Index's parent should be Table1 in the existing database");
}
示例11: The_Original_Database_Should_Contain_A_Copy_Of_The_New_Index
public void The_Original_Database_Should_Contain_A_Copy_Of_The_New_Index()
{
var db1 = TestDatabaseLoader.TestDatabase();
// Setup new key information
Table parentTable = new Table("Table1");
parentTable.AddColumn(new Column("Column3"));
Index newIndex = new Index("UQ_Column3");
newIndex.Parent = parentTable;
newIndex.AddColumn("Column3");
IndexAdditionOperation op = new IndexAdditionOperation(db1.Tables[0], newIndex);
op.RunOperation();
op.RunSecondStep();
Assert.That(db1.Tables[0].Indexes, Has.Count(2));
Assert.That(db1.Tables[0].Indexes[1].Name, Is.EqualTo(newIndex.Name));
Assert.That(db1.Tables[0].Indexes[1], Is.Not.SameAs(newIndex), "The added Index should be a copy, not the original object.");
Assert.That(db1.Tables[0].Indexes[1].Columns[0], Is.SameAs(db1.Tables[0].Columns[2]), "The new Index should reference existing columns, not the new ones");
Assert.That(db1.Tables[0].Indexes[1].Parent, Is.SameAs(db1.Tables[0]), "The new Index's parent should be Table1 in the existing database");
}