【发布时间】:2021-12-11 03:24:48
【问题描述】:
我正在使用 FluentMigrator 将多个数据库迁移到不同的架构。
如何检查某个列是否存在于另一个数据库的表中?
public override void Up()
{
//this line by default uses the current DB context and it works fine
var columnExistsInThisDb = Schema.Table("Subjects").Column("MatterKey").Exists();
//here I would like to check if column exist in "AnotherDatabase",
//but I didn't manage to make it work
var columnExistsInAnotherDb =
Database("AnotherDatabase") //<--- this is pseudo-code of what I would like to achieve
.Schema.Table("Subjects").Column("MatterKey").Exists();
if (columnExistsInThisDb || columnExistsInAnotherDb)
{
Execute.Sql("--DO STUFF");
}
}
我尝试了以下方法,但即使列存在,它也会返回 FALSE。
var columnExistsInAnotherDb = Schema.Table("AnotherDatabase.dbo.Subjects").Column("MatterKey").Exists()
【问题讨论】:
标签: c# sql fluent-migrator