C#C
C#4y ago
pwnage

Drop composite PK and add new column PK with identity with EF Code first

Hello. I have following table ClaimFeeType(picture below).
I want to remove composite PK constraint and add new column and assign identity PK to it withtou losing data. I achieved that with pure SQL in MSSQL studio following way:
BEGIN TRAN
ALTER TABLE dbo.ClaimFeeType
DROP CONSTRAINT PK_ClaimFeeType;
ALTER TABLE dbo.ClaimFeeType ADD ClaimFeeTypeId int identity(1,1) not null
GO
ALTER TABLE dbo.ClaimFeeType
add CONSTRAINT PK_ClaimFeeTypeId primary key(ClaimFeeTypeId)
GO
ROLLBACK TRAN


But I am not sure how to do that with EF Code first migrations, as my code base uses Entity Framework. All in all, my database is already in production so can't afford losing data, want to remove composite key PK, add new int column PK with auto increment, and populate new PK field with values. Done with MSSQL, don't know how to write migration for EF.
unknown.png
Was this page helpful?