我在一个asp.net web api项目上使用VS2013和一个部署在Azure上的实体框架
我试图改变其中一个表上的键,而不是由2个由3个键组成的外键组成。使用Add-Migration
命令生成以下迁移
public partial class ChangeKeys_v4 : DbMigration
{
public override void Up()
{
DropPrimaryKey("dbo.MyTable");
AddPrimaryKey("dbo.MyTable", new[] { "ClientId", "Order", "ZoneId" });
}
public override void Down()
{
DropPrimaryKey("dbo.MyTable");
AddPrimaryKey("dbo.MyTable", new[] { "ClientId", "ZoneId" });
}
}
这是更改为包含订单作为键的实体类:
public class MyTable
{
[Key, Column(Order = 1), ForeignKey("Client")]
public int ClientId { get; set; }
[Key, Column(Order = 2)]
public int Order { get; set; }
[Key, Column(Order = 3), ForeignKey("Zone")]
public string ZoneId { get; set; }
public virtual Client Client { get; set; }
public virtual Zone Zone { get; set; }
public MyTable() { }
public MyTable(Client c, int o, Zone z)
{
Client = c;
Order = o;
Zone = z;
}
}
我已经在我的开发环境中成功Update-Database
了,但是在文本环境中这样做时出现以下错误
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
Could not drop constraint. See previous errors.
The statement has been terminated.
我可以对我的migation类进行哪些更改以使其正常工作。
我已经看到了一些解决方案,并且大多数人都说要放弃桌面,而且当我必须推向生产环境时,这不是一个真正的选择。
答案 0 :(得分:1)
对于托管数据库的Azure,您无法为此更改执行EF代码 - >数据库升级。
首先,你必须要有停机时间。然后在SSMS中运行连接到Azure DB的脚本。该脚本将:
也许会延迟第5步,直到用户确定它已经完成测试后才能确定它。