IT:AD:EF/CodeFirst:HowTo:Migrations
- IT:EF/CodeFirst:HowTo:Migrations
- See also:
Summary
If you have a table that has a Guid PrimaryKey, and you create a table that references it via an FK (therefore gets a Guid FK property)… and then you decide to change it to an int based relationship..
Process
You're truly FUBAR.
EDIT: The basis of the problem is that the Id is the Clustered Index – the order in which the rows are actually ordered in the table. And SQL Server doesn't allow you to change a tables clustered index, without dropping/recreating the table.
I never got the whole way through, but so far:
- Drop the FK between the two.
- Drop the index of the Primary table.
- Drop the Default value (that generated the NEWSEQUENTIALID()) – that part i could not work out.
- Change the Principal Id type.
- Change the Dependent Id type.
- Create the index to the primary table.
- Create the relationship between the two.
The solution I did was: punch the screen.
- Add mappings to Ignore the Entities
- Dropped any FK properties on Dependents tables.
- Generated the Migration.
- Readded the table.
- Grrr.