实体框架多对多聚集索引与非聚集索引

发布于 2024-09-15 23:33:47 字数 202 浏览 2 评论 0原文

我设计了一个实体数据模型,其中两个实体之间存在多对多关系。当我自动生成 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月松间行 2024-09-22 23:33:47

我有另一个名为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文