问题
I Have defined an entity class with a key, but I don,t want that key be cluster because I have another cluster index in my entity, but I received an error when I add an Index attribute to my model,
Can anybody tell me that how can I define a Non-Clustered Key????
回答1:
AFAIK it is still not possible to create non-clustered primary key fields as part of your code first configuration.
However, if you are using migrations or are in a position where you are able to, see the following Entity Framework work item that goes through a solution using code first migrations (as well as the thinking behind no direct code first support):
http://entityframework.codeplex.com/workitem/614
This related question has some information as well: EF CodeFirst create non-clustered primary key index. It is for EF 4.1 but still relevant to EF 6.
来源:https://stackoverflow.com/questions/24924752/entity-framework-code-first-define-the-non-clustered-key-for-this-entitytype