We’ve been using a complex type CreditCardTransaction associated with our purchase orders. It really should have been it’s own entity, and I am trying to fix this now.
How would you write a migration from this:
[ComplexType()]
public class CreditCardTransaction
{
public String SomeTransactionData { get; set; }
}
into this entity:
public class CreditCardTransaction
{
public int Id { get; set; }
public String SomeTransactionData { get; set; }
}
This is what is generated for me. Can I easily move the data in the original table to the other table?
public partial class test : DbMigration
{
public override void Up()
{
CreateTable(
"CreditCardTransactions",
c => new
{
Id = c.Int(nullable: false, identity: true),
SomeTransactionData = c.String()
})
.PrimaryKey(t => t.Id);
AddColumn("PurchaseOrder", "Transaction_Id", c => c.Int());
AddForeignKey("PurchaseOrder", "Transaction_Id", "CreditCardTransactions", "Id");
CreateIndex("PurchaseOrders", "Transaction_Id");
DropColumn("PurchaseOrders", "Transaction_SomeTransactionData");
}
// Down() snipped
}
I believe you can. Modify your
Upmethod and prior to callDropColumnuseSqlmethod with custom SQL transferring data fromPurchaseOrderstoCreditTransactionsand fixing FK relationships.