Well, I was a little bit hesitant to post the solution I ended up going with, because it feels like a bit of a hack, but since I don't really expect any other answers at this point, here it is.
I ended up hand-editing the migration with this method. Essentially, I'm dropping the constraints, doing an update query to get an nvarchar representation of the integer key, then converting to an int and adding the constraints again.
public override void Up()
{
DropIndex("dbo.ValueSetElements", new[] { "Parent_Id" });
DropIndex("dbo.SectionElements", new[] { "Choices_Id" });
DropForeignKey("dbo.ValueSetElements", "Parent_Id", "dbo.ValueSets");
DropForeignKey("dbo.SectionElements", "Choices_Id", "dbo.ValueSets");
DropPrimaryKey(ValueSetTable, "PK_dbo.ValueSets");
RenameColumn(ValueSetTable, "Id", "Hash");
AddColumn(ValueSetTable, "Id", c => c.Int(nullable: false, identity: true, name: "Id"));
AddPrimaryKey(ValueSetTable, "Id");
CreateIndex(ValueSetTable, "Hash");
Sql("UPDATE dbo.SectionElements SET Choices_Id = CONVERT(nvarchar(10), (SELECT Id FROM dbo.ValueSets WHERE dbo.ValueSets.Hash = dbo.SectionElements.Choices_Id))");
AlterColumn("dbo.SectionElements", "Choices_Id", c => c.Int());
AddForeignKey("dbo.SectionElements", "Choices_Id", "dbo.ValueSets", "Id");
CreateIndex("dbo.SectionElements", "Choices_Id");
Sql("ALTER TABLE dbo.ValueSetElements DROP CONSTRAINT [DF__ValueSetE__Paren__0F63164F]");
Sql("UPDATE dbo.ValueSetElements SET Parent_Id = CONVERT(nvarchar(10), (SELECT Id FROM dbo.ValueSets WHERE dbo.ValueSets.Hash = dbo.ValueSetElements.Parent_Id))");
AlterColumn("dbo.ValueSetElements", "Parent_Id", c => c.Int(nullable: false));
AddForeignKey("dbo.ValueSetElements", "Parent_Id", ValueSetTable, "Id", cascadeDelete: true);
CreateIndex("dbo.ValueSetElements", "Parent_Id");
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…