All*_*lan 6 entity-framework naming-conventions ef-code-first entity-framework-6.1
我了解如何将约定添加到代码优先(通过迁移)项目。我已经成功地执行了表名称,甚至将 GUID Id 字段更改为非聚集。
但我还没有找到如何在未给出名称时更改 EF 提供的默认索引名称。
[Index(IsUnique = true)]
public string Code { get; set; }
[Index]
public string Description { get; set; }
Run Code Online (Sandbox Code Playgroud)
我有这两个要求。顶部索引应命名为UX_[schema]_[table]_Code,第二个索引应命名为IX_[schema]_[table]_Description
我还需要支持多列索引,其中 IsUnique 仍然是 UX,但列部分是所有列的驼峰式组合(例如, UX_[schema]_[table]_CodeDescription如果上面的两列位于同一索引中)。
我假设我需要在 IndexAttributeConvention 之后添加它,以便所有当前功能都可以工作并创建 IndexAnnotations。但如果属性(或 Fluent 构造)中留空,我无法找到索引在哪里接收其初始名称。
提前致谢。
小智 -1
您是否尝试过此注释:[Index("IndexName")] 或您的示例:
[Index("IndexName", IsUnique = true)]
public string Code { get; set; }
Run Code Online (Sandbox Code Playgroud)