How to change a clustered index in Entity Framework 6.1 Code First model and apply it to an Azure database

后端 未结 4 1014
闹比i
闹比i 2021-01-18 10:31

Using the Entity Framework 6.1 code first model, what is the best way to go about changing the clustered index on a table from the default ID to another set of columns. Azur

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 11:12

    You need to remove the existing clustered index from your current PK 'ID' which is created by default for any "KEY" property in code first. It can be done using fluent API:

    .Primarykey(x=>x.ID,clustered:false)
    

    Once existing clustered index is removed from ID, your migration to add the clustered index on UserID should run smoothly.

提交回复
热议问题