实体框架代码优先 - 为此EntityType定义非群集密钥 [英] Entity Framework Code-First - Define the Non-clustered key for this EntityType

查看:104
本文介绍了实体框架代码优先 - 为此EntityType定义非群集密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用一个关键字定义了一个实体类,但是我不希望这个关键字是集群的,因为我的实体中有另一个
的集群索引,但是当我将Index属性添加到我的时候收到一个错误模型,



有人可以告诉我如何定义一个非群集密钥

解决方案

AFAIK仍然无法创建非群集主键字段作为代码首次配置的一部分。



但是,如果您使用迁移或处于您可以的位置,请参阅使用代码首次迁移

的以下实体框架工作项, strong>(以及没有直接代码支持的思考):



http://entityframework.codeplex.com/workitem/614



此相关问题也有一些信息:一个href =https://stackoverflow.com/questions/6813462/ef-codefirst-create-non-clustered-primary-key-index> EF CodeFirst创建非群集主键索引。它是EF 4.1,但仍然与EF 6相关。


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????

解决方案

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.

这篇关于实体框架代码优先 - 为此EntityType定义非群集密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆