本文整理汇总了C#中IQuery.AddForeignKey方法的典型用法代码示例。如果您正苦于以下问题:C# IQuery.AddForeignKey方法的具体用法?C# IQuery.AddForeignKey怎么用?C# IQuery.AddForeignKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQuery
的用法示例。
在下文中一共展示了IQuery.AddForeignKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTables
private void CreateTables(IQuery query, string testsName)
{
var columns = new List<SqlTableColumn> {
new SqlTableColumn("id", PrimitiveTypes.Integer()),
new SqlTableColumn("name", PrimitiveTypes.String())
};
if (testsName.Equals("NotNullColumnViolation"))
columns.Add(new SqlTableColumn("age", PrimitiveTypes.Integer()) {
IsNotNull = true
});
query.CreateTable(new ObjectName("a"), columns.ToArray());
query.AddPrimaryKey(new ObjectName("a"), new []{"id"});
query.AddUniqueKey(new ObjectName("a"), new[] {"name"});
query.CreateTable(new ObjectName("b"), new SqlTableColumn("id", PrimitiveTypes.Integer()),
new SqlTableColumn("other_id", PrimitiveTypes.Integer()));
query.AddPrimaryKey(new ObjectName("b"), new[] {"id"});
query.AddForeignKey(new ObjectName("b"), new[] {"other_id"}, new ObjectName("a"), new[] {"id"},
ForeignKeyAction.Cascade, ForeignKeyAction.NoAction);
}
示例2: CreateTestTables
private void CreateTestTables(IQuery context)
{
var tn1 = ObjectName.Parse("APP.test_table1");
var tableInfo1 = new TableInfo(tn1);
tableInfo1.AddColumn(new ColumnInfo("id", PrimitiveTypes.Integer()));
tableInfo1.AddColumn(new ColumnInfo("name", PrimitiveTypes.String()));
tableInfo1.AddColumn(new ColumnInfo("date", PrimitiveTypes.DateTime()));
context.CreateTable(tableInfo1);
context.AddPrimaryKey(tn1, "id");
var tn2 = ObjectName.Parse("APP.test_table2");
var tableInfo2 = new TableInfo(tn2);
tableInfo2.AddColumn(new ColumnInfo("id", PrimitiveTypes.Integer()));
tableInfo2.AddColumn(new ColumnInfo("other_id", PrimitiveTypes.Integer()));
tableInfo2.AddColumn(new ColumnInfo("count", PrimitiveTypes.Integer()));
context.CreateTable(tableInfo2);
context.AddPrimaryKey(tn2, "id");
context.AddForeignKey(tn2, new[] { "other_id" }, tn1, new[] { "id" }, ForeignKeyAction.Cascade, ForeignKeyAction.Cascade, null);
}