本文整理汇总了C#中Table.AddKey方法的典型用法代码示例。如果您正苦于以下问题:C# Table.AddKey方法的具体用法?C# Table.AddKey怎么用?C# Table.AddKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.AddKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTable
private static ITable CreateTable(IDatabase db, string tableName)
{
var table = new Table(tableName);
table.AddColumn(new Column("Column1"));
table.AddColumn(new Column("Column2"));
table.AddColumn(new Column("Column3"));
var primaryKey = new Key("PrimaryKey", DatabaseKeyType.Primary);
table.AddKey(primaryKey);
var foreignKey = new Key("ForeignKey", DatabaseKeyType.Foreign);
table.AddKey(foreignKey);
primaryKey.AddColumn("Column1");
foreignKey.AddColumn("Column1");
db.AddTable(table);
return table;
}
示例2: 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;
}
示例3: It_Should_Be_Reconstructed_Correctly
public void It_Should_Be_Reconstructed_Correctly()
{
const string xml = When_Serialising_Key_With_A_Referenced_Key.KeyWithReferencedKeyXml;
XmlDocument document = new XmlDocument();
document.LoadXml(xml);
Database db = new Database("Database1");
Table table1 = new Table("Table1");
Table table2 = new Table("Table2");
db.AddTable(table1);
db.AddTable(table2);
IKey key2 = new Key("ForeignKey") { Parent = table2 };
table2.AddKey(key2);
var scheme = new DatabaseDeserialisationScheme();
IKey key = scheme.ProcessKeyNode(document.DocumentElement, table1, db);
scheme.ProcessReferencedKey(key, document.DocumentElement, db);
Assert.That(key.ReferencedKey, Is.SameAs(key2));
}
示例4: 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));
}
示例5: It_Should_Be_Reconstructed_Correctly
public void It_Should_Be_Reconstructed_Correctly()
{
IDatabase database = new Database("DB1");
var table1 = new Table("Table1");
var table2 = new Table("Table2");
var key1 = new Key("K1", DatabaseKeyType.Primary);
var key2 = new Key("ForeignKey", DatabaseKeyType.Foreign);
table1.AddKey(key1);
table2.AddKey(key2);
database.AddTable(table1);
database.AddTable(table2);
Relationship rel = new DatabaseDeserialisationScheme().DeserialiseRelationship(FullRelationshipXml.GetXmlDocRoot(), database);
Assert.That(rel.Identifier, Is.EqualTo(new Guid("11111111-1111-1111-1111-111111111111")));
Assert.That(rel.Name, Is.EqualTo("Relation1"));
Assert.That(rel.PrimaryTable, Is.SameAs(table1));
Assert.That(rel.ForeignTable, Is.SameAs(table2));
Assert.That(rel.PrimaryKey, Is.SameAs(key1));
Assert.That(rel.ForeignKey, Is.SameAs(key2));
}
示例6: GetDb
internal static Database GetDb()
{
var db = TestDatabaseLoader.TestDatabase();
Table table2 = new Table("Table2");
table2.AddColumn(new Column("Column1"));
table2.AddColumn(new Column("Column2"));
table2.AddColumn(new Column("Column3"));
Key foreignKey = new Key("FK_Table2", DatabaseKeyType.Foreign);
foreignKey.Parent = table2;
foreignKey.ReferencedKey = db.Tables[0].Keys[0];
foreignKey.AddColumn("Column1");
foreignKey.AddColumn("Column2");
table2.AddKey(foreignKey);
db.AddTable(table2);
new DatabaseProcessor().CreateRelationships(db);
return db;
}
示例7: It_Returns_The_IKey_Objects
public void It_Returns_The_IKey_Objects()
{
ProviderInfo info = new ProviderInfo();
var table1 = new Table();
var index1 = new Key("1");
table1.AddKey(index1);
var table2 = new Table();
var index2 = new Key("2");
table2.AddKey(index2);
info.MappingSet.Database.AddTable(table1);
info.MappingSet.Database.AddTable(table2);
IEnumerable<IScriptBaseObject> objects = info.GetAllObjectsOfType(typeof(IKey));
Assert.That(objects, Has.Length(2));
Assert.That(objects.Contains(index1));
Assert.That(objects.Contains(index2));
}
示例8: Should_Return_This
public void Should_Return_This()
{
const string expectedXML = "<Table>" + When_Serialising_An_Empty_Table.ScriptBaseXml +
"<Keys>" + When_Serialising_An_Empty_Key.BasicKeyXml + "</Keys>" +
"</Table>";
Table table = new Table("Entity1");
table.AddKey(new Key("PrimaryKey"));
string outputXML = table.Serialise(new DatabaseSerialisationScheme());
outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML);
Assert.That(outputXML, Is.EqualTo(expectedXML));
}
示例9: 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]);
}