In Entity Framework Code First approach, can we define the Primary Key as non-clustered index and a combination of few other fields as clustered index.
Thanks
Yes you can, by specifying the primary key be nonclustered.
The answer is NO. It is not possible at all. If I have to say in the most simple words, Primary Keys exists with either Clustered Index or Non-Clustered Index.
Taking all this into consideration, you cannot alter an index to make it clustered. However, you can create a new one so long as one does not already exist. Either that or drop the clustered index, create your new clustered index and then create your old clustered index as a non clustered index.
EF 6.2 resolved this issue. Currently, it's in beta state, but it works.
First, upgrade your EF to 6.2:
Install-Package EntityFramework -Version 6.2.0-beta1 -Pre
Then, in the OnModelCreating
method, set the IsClustered to false
for the primary key:
modelBuilder.Entity<Receipt>().HasKey(r => r.RecId, config => config.IsClustered(false) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With