实体框架多对多聚集索引与非聚集索引
我设计了一个实体数据模型,其中两个实体之间存在多对多关系。当我自动生成 SQL 代码来生成该模型的数据库时,它生成了一个表(两列)来跟踪这个多对多关联。但是,该表的两列上都有一个 PRIMARY KEY NONCLUSTERED。
由于我希望它能够在 SQL Azure 上运行,它不喜欢仅包含非聚集索引的表,所以我想知道是否有一种好的方法来告诉代码生成生成聚集索引?谢谢!
I designed an entity data model with two entities between which there exists a many to many relationship. When I auto-generate SQL code to generate the database for this model, it has generated a table (two columns) to keep track of this many-to-many association. However, this table has a PRIMARY KEY NONCLUSTERED on both columns.
Since I want this to work on SQL Azure which doesn't like tables with only nonclustered indices, I was wondering whether there is a good way of telling the code generation to generate clustered indices? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有另一个名为 Model.indexes.sql 的文件,其中包含用于创建 EF 生成的基本索引之外的其他索引的脚本,例如用于性能优化的索引。
尽管这并不理想,但我在其中添加了索引删除并为每个 EF 关联创建,以将非聚集索引转换为索引索引:
ALTER TABLE [dbo].[MyAssociation]
删除约束 [PK_MyAssociation]
去
更改表 [dbo].[MyAssociation]
添加约束 [PK_MyAssociation]
主键聚集([Table1_Id],[Table2_Id] ASC);
GO
这在每个“从模型生成数据库...”之后执行。我想要一个更优雅的解决方案。
I have another file called Model.indexes.sql that contains scripts to create additional indexes beyond the basic ones EF generates, such as those for performance optimizations.
Although this is not ideal, I added into this an index drop and create for each EF association to convert the Non-Clustered indexes into indexed ones:
ALTER TABLE [dbo].[MyAssociation]
DROP CONSTRAINT [PK_MyAssociation]
GO
ALTER TABLE [dbo].[MyAssociation]
ADD CONSTRAINT [PK_MyAssociation]
PRIMARY KEY CLUSTERED ([Table1_Id], [Table2_Id] ASC);
GO
This is executed after every "Generate Database from Model...". I would love a more elegant solution.