【发布时间】:2014-11-12 06:29:02
【问题描述】:
我了解如何在代码优先(使用迁移)项目中添加约定。我已经成功地执行了表名,甚至将 GUID Id 字段更改为非集群。
但我还没有找到在没有给出名称时如何更改 EF 提供的默认索引名称。
[Index(IsUnique = true)]
public string Code { get; set; }
[Index]
public string Description { get; set; }
我有这两个要求。顶部索引应命名为UX_[schema]_[table]_Code,第二个索引应命名为IX_[schema]_[table]_Description
我还需要支持多列索引,其中 IsUnique 仍将是 UX,但列部分是所有列的驼峰式组合(例如 UX_[schema]_[table]_CodeDescription,如果上面的两列在同一个索引中。
我假设我需要在 IndexAttributeConvention 之后添加它,以便所有当前功能都可以工作并创建 IndexAnnotations。但是如果在属性(或流利的构造)中留空,我找不到索引在哪里接收它们的初始名称。
提前致谢。
【问题讨论】:
标签: entity-framework ef-code-first naming-conventions entity-framework-6.1