本文整理汇总了C#中DatabaseSchemaReader.DataSchema.DatabaseTable.AddConstraint方法的典型用法代码示例。如果您正苦于以下问题:C# DatabaseTable.AddConstraint方法的具体用法?C# DatabaseTable.AddConstraint怎么用?C# DatabaseTable.AddConstraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseSchemaReader.DataSchema.DatabaseTable
的用法示例。
在下文中一共展示了DatabaseTable.AddConstraint方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WithBidirectionalDepndencyTopologicalSort
public void WithBidirectionalDepndencyTopologicalSort()
{
//arrange
var schema = new DatabaseSchema(null, null);
var orders = new DatabaseTable();
orders.Name = "countries";
var productsFk = new DatabaseConstraint();
productsFk.ConstraintType = ConstraintType.ForeignKey;
productsFk.RefersToTable = "capitalcities";
orders.AddConstraint(productsFk);
schema.Tables.Add(orders);
var products = new DatabaseTable();
products.Name = "capitalcities";
var categoriesFk = new DatabaseConstraint();
categoriesFk.ConstraintType = ConstraintType.ForeignKey;
categoriesFk.RefersToTable = "countries";
products.AddConstraint(categoriesFk);
schema.Tables.Add(products);
//a country has one capital city
//a capital city is in one country
//But bidirectional foreign keys is terrible database design - you really only need one direction.
//(you have to save the country with a null capital, then the capital, then update the country again).
//Topological sorts don't support cycles, so we should just get back the original list
//act
var sortedTables = SchemaTablesSorter.TopologicalSort(schema);
//assert
Assert.AreEqual(2, sortedTables.Count());
//non-deterministic order
}
示例2: TestSqlServerCheckConstraint
public void TestSqlServerCheckConstraint()
{
//arrange
var table = new DatabaseTable {Name = "Orders"};
var check = new DatabaseConstraint
{
ConstraintType = ConstraintType.Check,
Expression = "[Quantity] > 0",
Name = "ValidationRule"
};
table.AddConstraint(check);
var writer = new ConstraintWriter(table);
//act
var txt = writer.WriteCheckConstraints();
//assert
Assert.IsTrue(txt.Contains("ALTER TABLE [Orders] ADD CONSTRAINT [ValidationRule] CHECK ([Quantity] > 0);"));
}
示例3: TestAccessDateCheckConstraint
public void TestAccessDateCheckConstraint()
{
//arrange
var table = new DatabaseTable {Name = "Orders"};
var check = new DatabaseConstraint
{
ConstraintType = ConstraintType.Check,
Expression = ">Date()",
Name = "[Orders].[OrderDate].ValidationRule"
};
table.AddConstraint(check);
var writer = new TableGenerator(table);
//act
var txt = writer.Write();
//assert
Assert.IsTrue(txt.Contains("ALTER TABLE [Orders] ADD CONSTRAINT [Orders_OrderDate_ValidationRule] CHECK ([Orders].[OrderDate] >getdate());"));
}
示例4: TestTopologicalSort
public void TestTopologicalSort()
{
//arrange
var schema = new DatabaseSchema(null, null);
var orders = new DatabaseTable();
orders.Name = "orders";
var productsFk = new DatabaseConstraint
{
ConstraintType = ConstraintType.ForeignKey,
RefersToTable = "products"
};
orders.AddConstraint(productsFk);
schema.Tables.Add(orders);
var categories = new DatabaseTable();
categories.Name = "categories";
schema.Tables.Add(categories);
var products = new DatabaseTable();
products.Name = "products";
var categoriesFk = new DatabaseConstraint();
categoriesFk.ConstraintType = ConstraintType.ForeignKey;
categoriesFk.RefersToTable = "categories";
products.AddConstraint(categoriesFk);
schema.Tables.Add(products);
//act
var sortedTables = SchemaTablesSorter.TopologicalSort(schema);
//assert
var first = sortedTables.First();
var last = sortedTables.Last();
Assert.AreEqual(categories, first);
Assert.AreEqual(orders, last);
}