简体   繁体   English

将聚簇索引与主键分离的实体框架

[英]Entity Framework separating clustered index from primary key

I have a table schema where the primary key is a uniqueidentifier , and the clustered index is an identity column of type bigint . 我有一个表模式,其中主键是uniqueidentifier ,聚簇索引是bigint类型的标识列。

The idea is that the Guid index is likely going to be fragmented and if it's going to be fragmented I prefer that it's not the clustered index because then it would really slow down insert. 这个想法是Guid索引可能会碎片化,如果它会碎片化,我更喜欢它不是聚集索引,因为它会真的减慢插入。 Ie I want the row inserted sequentially as much as possible. 即我希望尽可能顺序插入行。

However I do NOT want the clustered index propagated to the conceptual layer in EF. 但是,我不希望聚集索引传播到EF中的概念层。 The clustered index is simply the physical location of the so said record and the programmers don't need to know anything about it. 聚集索引只是所述记录的物理位置,程序员不需要了解它。 As far as they are concerned they are only dealing with the Guid PK. 就他们而言,他们只处理Guid PK。 So I removed the property from the models. 所以我从模型中删除了属性。

The project compilation complains however that the clustered index column is non nullable, and has no default value, either of which is nonsensical considering it is an identity column and can neither have a default value or be nullable. 然而,项目编译抱怨聚集索引列不可为空,并且没有默认值,考虑到它是一个标识列,它们都是无意义的,既不能有默认值也不能为空。

What can I do to get the project to compile? 我该怎么做才能让项目编译?

Note: I do not want a debate about Guid vs. Sequential Guid vs. Int Id. 注意:我不想讨论Guid vs. Sequential Guid vs. Int Id。 This system must be able to scale out and that means Guid PK where I'm concerned. 这个系统必须能够扩展,这意味着我所关心的Guid PK。

您应该检查EDMX中属性的EntityKey值是否设置为true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM