本文整理汇总了C#中FluentMigrator.Expressions.CreateForeignKeyExpression类的典型用法代码示例。如果您正苦于以下问题:C# CreateForeignKeyExpression类的具体用法?C# CreateForeignKeyExpression怎么用?C# CreateForeignKeyExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreateForeignKeyExpression类属于FluentMigrator.Expressions命名空间,在下文中一共展示了CreateForeignKeyExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCreateForeignKeyExpression
public static CreateForeignKeyExpression GetCreateForeignKeyExpression()
{
var expression = new CreateForeignKeyExpression();
expression.ForeignKey.Name = "FK_Test";
expression.ForeignKey.PrimaryTable = TestTableName2;
expression.ForeignKey.ForeignTable = TestTableName1;
expression.ForeignKey.PrimaryColumns = new[] { TestColumnName2 };
expression.ForeignKey.ForeignColumns = new[] { TestColumnName1 };
return expression;
}
示例2: CanCreateForeignKey
public void CanCreateForeignKey()
{
var expression = new CreateForeignKeyExpression();
expression.ForeignKey.Name = "FK_Test";
expression.ForeignKey.PrimaryTable = "TestPrimaryTable";
expression.ForeignKey.ForeignTable = "TestForeignTable";
expression.ForeignKey.PrimaryColumns = new[] { "Column1", "Column2" };
expression.ForeignKey.ForeignColumns = new[] { "Column3", "Column4" };
string sql = generator.Generate(expression);
sql.ShouldBe("ALTER TABLE TestForeignTable ADD CONSTRAINT FK_Test FOREIGN KEY (Column3,Column4) REFERENCES TestPrimaryTable (Column1,Column2)");
}
示例3: CanCreateForeignKey
public void CanCreateForeignKey()
{
var expression = new CreateForeignKeyExpression();
expression.ForeignKey.Name = "FK_Test";
expression.ForeignKey.PrimaryTable = "TestPrimaryTable";
expression.ForeignKey.ForeignTable = "TestForeignTable";
expression.ForeignKey.PrimaryColumns = new[] { "Column1", "Column2" };
expression.ForeignKey.ForeignColumns = new[] { "Column3", "Column4" };
var sql = generator.Generate(expression);
sql.ShouldBe(
"ALTER TABLE [TestForeignTable] ADD CONSTRAINT FK_Test FOREIGN KEY ([Column3],[Column4]) REFERENCES [TestPrimaryTable] ([Column1],[Column2])");
}
示例4: Generate
public override string Generate(CreateForeignKeyExpression expression)
{
string primaryColumns = GetColumnList(expression.ForeignKey.PrimaryColumns);
string foreignColumns = GetColumnList(expression.ForeignKey.ForeignColumns);
string sql = "ALTER TABLE {0} ADD CONSTRAINT {1} FOREIGN KEY ({2}) REFERENCES {3} ({4})";
return String.Format(sql,
expression.ForeignKey.ForeignTable,
expression.ForeignKey.Name,
foreignColumns,
expression.ForeignKey.PrimaryTable,
primaryColumns
);
}
示例5: ToStringIsDescriptive
public void ToStringIsDescriptive()
{
var sql = new CreateForeignKeyExpression
{
ForeignKey = new ForeignKeyDefinition
{
ForeignColumns = new Collection<string> { "User_id" },
ForeignTable = "UserRoles",
PrimaryColumns = new Collection<string> { "Id" },
PrimaryTable = "User",
Name = "FK"
}
}.ToString();
sql.ShouldBe("CreateForeignKey FK UserRoles(User_id) User(Id)");
}
示例6: Generate
public override string Generate(CreateForeignKeyExpression expression)
{
var primaryColumns = GetColumnList(expression.ForeignKey.PrimaryColumns);
var foreignColumns = GetColumnList(expression.ForeignKey.ForeignColumns);
const string sql = "ALTER TABLE {0}[{1}] ADD CONSTRAINT {2} FOREIGN KEY ({3}) REFERENCES {4}[{5}] ({6})";
return string.Format(sql,
FormatSchema(expression.ForeignKey.ForeignTableSchema),
expression.ForeignKey.ForeignTable,
expression.ForeignKey.Name,
foreignColumns,
FormatSchema(expression.ForeignKey.PrimaryTableSchema),
expression.ForeignKey.PrimaryTable,
primaryColumns
);
}
示例7: Generate
public override string Generate(CreateForeignKeyExpression expression)
{
string primaryColumns = GetColumnList(expression.ForeignKey.PrimaryColumns);
string foreignColumns = GetColumnList(expression.ForeignKey.ForeignColumns);
string sql = "ALTER TABLE `{0}` ADD CONSTRAINT {1} FOREIGN KEY ({2}) REFERENCES {3} ({4}){5}{6}";
return String.Format(sql,
expression.ForeignKey.ForeignTable,
expression.ForeignKey.Name,
foreignColumns,
expression.ForeignKey.PrimaryTable,
primaryColumns,
FormatCascade("DELETE", expression.ForeignKey.OnDelete),
FormatCascade("UPDATE", expression.ForeignKey.OnUpdate)
);
}
示例8: Generate
public override string Generate(CreateForeignKeyExpression expression)
{
var primaryColumns = GetColumnList(expression.ForeignKey.PrimaryColumns);
var foreignColumns = GetColumnList(expression.ForeignKey.ForeignColumns);
const string sql = "ALTER TABLE {0}.{1} ADD CONSTRAINT {2} FOREIGN KEY ({3}) REFERENCES {4}.{5} ({6}){7}{8}";
return string.Format(sql,
Quoter.QuoteSchemaName(expression.ForeignKey.ForeignTableSchema),
Quoter.QuoteTableName(expression.ForeignKey.ForeignTable),
Quoter.Quote(expression.ForeignKey.Name),
foreignColumns,
Quoter.QuoteSchemaName(expression.ForeignKey.PrimaryTableSchema),
Quoter.QuoteTableName(expression.ForeignKey.PrimaryTable),
primaryColumns,
FormatCascade("DELETE", expression.ForeignKey.OnDelete),
FormatCascade("UPDATE", expression.ForeignKey.OnUpdate)
);
}
示例9: Truncate
public void Truncate(CreateForeignKeyExpression expression)
{
Truncate(expression.ForeignKey);
}
示例10: Generate
public override string Generate(CreateForeignKeyExpression expression)
{
return string.Format("{0};", base.Generate(expression));
}
示例11: GenerateForeignKeyName
public virtual string GenerateForeignKeyName(CreateForeignKeyExpression expression)
{
return string.Format("FK_{0}_{1}", expression.ForeignKey.PrimaryTable.Substring(0, 5), expression.ForeignKey.ForeignTable.Substring(0, 5));
}
示例12: ForeignKey
public ICreateForeignKeyFromTableSyntax ForeignKey()
{
var expression = new CreateForeignKeyExpression();
_context.Expressions.Add(expression);
return new CreateForeignKeyExpressionBuilder(expression);
}
示例13: Generate
public override string Generate(CreateForeignKeyExpression expression)
{
return compatabilityMode.HandleCompatabilty("Forign keys are not supported in Sqlite");
}
示例14: CanForeignKeyToUniqueColumn
public void CanForeignKeyToUniqueColumn()
{
// Arrange
var create = new CreateTableExpression
{
TableName = "Foo",
Columns = new[]{
new ColumnDefinition {Name = "Id", Type = DbType.Int32, IsPrimaryKey = true}
, new ColumnDefinition {Name = "Type", Type = DbType.Int32}
}
};
var index = new CreateIndexExpression
{
Index =
new IndexDefinition()
{
Name = "IDX_FooType",
TableName = "Foo",
IsUnique = true,
Columns = new List<IndexColumnDefinition> { new IndexColumnDefinition { Name = "Type" } }
}
};
var secondTable = new CreateTableExpression
{
TableName = "Bar",
Columns = new[]{
new ColumnDefinition {Name = "Id", Type = DbType.Int32, IsPrimaryKey = true}
, new ColumnDefinition {Name = "FooType", Type = DbType.Int32}
}
};
var foreignKey = new CreateForeignKeyExpression
{
ForeignKey =
new ForeignKeyDefinition()
{
Name = "FK_FooType",
ForeignTable = "Bar",
ForeignColumns = new [] { "FooType" },
PrimaryTable= "Foo",
PrimaryColumns = new[] { "Type" }
}
};
// Act
MigrateToOracleWithData(new List<IMigrationExpression> { create, index, secondTable, foreignKey }, 2);
// Assert
}
示例15: CallingOnUpdateSetsOnUpdateToSpecifiedRule
public void CallingOnUpdateSetsOnUpdateToSpecifiedRule(Rule rule)
{
var expression = new CreateForeignKeyExpression();
var builder = new CreateForeignKeyExpressionBuilder(expression);
builder.OnUpdate(rule);
Assert.That(expression.ForeignKey.OnUpdate, Is.EqualTo(rule));
Assert.That(expression.ForeignKey.OnDelete, Is.EqualTo(Rule.None));
}